@@ -70,7 +70,7 @@ protected function collectVars(Throwable $exception, int $statusCode): array
7070 $ trace = $ exception ->getTrace ();
7171
7272 if ($ this ->config ->sensitiveDataInTrace !== []) {
73- $ this ->maskSensitiveData ($ trace , $ this ->config ->sensitiveDataInTrace );
73+ $ trace = $ this ->maskSensitiveData ($ trace , $ this ->config ->sensitiveDataInTrace );
7474 }
7575
7676 return [
@@ -86,33 +86,50 @@ protected function collectVars(Throwable $exception, int $statusCode): array
8686
8787 /**
8888 * Mask sensitive data in the trace.
89+ */
90+ protected function maskSensitiveData (array $ trace , array $ keysToMask , string $ path = '' ): array
91+ {
92+ foreach ($ trace as $ i => $ line ) {
93+ $ trace [$ i ]['args ' ] = $ this ->maskData ($ line ['args ' ], $ keysToMask );
94+ }
95+
96+ return $ trace ;
97+ }
98+
99+ /**
100+ * @param array|object $args
89101 *
90- * @param array|object $trace
102+ * @return array|object
91103 */
92- protected function maskSensitiveData (& $ trace , array $ keysToMask , string $ path = '' ): void
104+ private function maskData ( $ args , array $ keysToMask , string $ path = '' )
93105 {
94106 foreach ($ keysToMask as $ keyToMask ) {
95107 $ explode = explode ('/ ' , $ keyToMask );
96108 $ index = end ($ explode );
97109
98110 if (strpos (strrev ($ path . '/ ' . $ index ), strrev ($ keyToMask )) === 0 ) {
99- if (is_array ($ trace ) && array_key_exists ($ index , $ trace )) {
100- $ trace [$ index ] = '****************** ' ;
101- } elseif (is_object ($ trace ) && property_exists ($ trace , $ index ) && isset ($ trace ->{$ index })) {
102- $ trace ->{$ index } = '****************** ' ;
111+ if (is_array ($ args ) && array_key_exists ($ index , $ args )) {
112+ $ args [$ index ] = '****************** ' ;
113+ } elseif (
114+ is_object ($ args ) && property_exists ($ args , $ index )
115+ && isset ($ args ->{$ index }) && is_scalar ($ args ->{$ index })
116+ ) {
117+ $ args ->{$ index } = '****************** ' ;
103118 }
104119 }
105120 }
106121
107- if (is_object ( $ trace )) {
108- $ trace = get_object_vars ( $ trace );
109- }
110-
111- if ( is_array ( $ trace )) {
112- foreach ($ trace as $ pathKey => $ subarray ) {
113- $ this ->maskSensitiveData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
122+ if (is_array ( $ args )) {
123+ foreach ( $ args as $ pathKey => $ subarray ) {
124+ $ args [ $ pathKey ] = $ this -> maskData ( $ subarray , $ keysToMask , $ path . ' / ' . $ pathKey );
125+ }
126+ } elseif ( is_object ( $ args )) {
127+ foreach ($ args as $ pathKey => $ subarray ) {
128+ $ args ->{ $ pathKey } = $ this ->maskData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
114129 }
115130 }
131+
132+ return $ args ;
116133 }
117134
118135 /**
0 commit comments