@@ -96,7 +96,7 @@ protected function traverseInputArray(array $inputArray, array $sensitiveKeys):
96
96
97
97
// If the value is not an array or an object, hash it if it is a sensitive key
98
98
if (is_scalar ($ value )) {
99
- if (in_array ( $ key , $ sensitiveKeys ) || array_key_exists ($ key , $ sensitiveKeys )) {
99
+ if ($ this -> isSensitiveKey ($ key , $ sensitiveKeys )) {
100
100
$ inputArray [$ key ] = $ this ->hash (print_r ($ value , true ));
101
101
}
102
102
@@ -105,7 +105,7 @@ protected function traverseInputArray(array $inputArray, array $sensitiveKeys):
105
105
106
106
// The value is either an array or an object, let traverse handle the specifics
107
107
// If the current key is a sensitive key, traverse the subtree.
108
- if (( in_array ( $ key , $ sensitiveKeys ) || array_key_exists ($ key , $ sensitiveKeys) )) {
108
+ if ($ this -> isSensitiveKey ($ key , $ sensitiveKeys )) {
109
109
// If the current key doesn't have a subtree of sensitive keys (indicating the entire subtree,
110
110
// and not a value somewhere in the subtree should be hashed)
111
111
if (!array_key_exists ($ key , $ sensitiveKeys )) {
@@ -191,4 +191,31 @@ protected function traverseObject(object $object, array $sensitiveKeys): object
191
191
192
192
return $ object ;
193
193
}
194
+
195
+ /**
196
+ * @param mixed $key
197
+ *
198
+ * @param array<array-key, mixed> $sensitiveKeys Keys to redact
199
+ *
200
+ * @return bool Whether the key provided is a sensitiveKey
201
+ */
202
+ protected function isSensitiveKey (mixed $ key , array $ sensitiveKeys ): bool
203
+ {
204
+ // Checks the values, if the key is in the value list of sensitive keys (the 'end' of the sensitive key lists)
205
+ if (in_array ($ key , $ sensitiveKeys )) {
206
+ return true ;
207
+ }
208
+
209
+ // When there is a sub array, check whether the key is in the sensitive key key list
210
+ if (array_key_exists ($ key , $ sensitiveKeys )) {
211
+ if (is_int ($ key )) {
212
+ // If the key is an integer, this is php generated key, when sensitiveKeys should be a value list
213
+ return false ;
214
+ }
215
+
216
+ return true ;
217
+ }
218
+
219
+ return false ;
220
+ }
194
221
}
0 commit comments