Skip to content

Commit

Permalink
MonitoredObject: Keep structure of nested cvs during protection
Browse files Browse the repository at this point in the history
fixes #4439

(cherry picked from commit d123b39)
  • Loading branch information
nilmerg committed Jul 21, 2021
1 parent 479f990 commit 78e947a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions modules/monitoring/library/Monitoring/Object/MonitoredObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,19 +466,22 @@ public static function protectCustomVars($customvars)
return $customvars;
}

$obfuscatedCustomVars = [];
$obfuscator = function ($vars) use ($blacklistPattern, &$obfuscatedCustomVars, &$obfuscator) {
$obfuscator = function ($vars) use ($blacklistPattern, &$obfuscator) {
$result = [];
foreach ($vars as $name => $value) {
if ($blacklistPattern && preg_match($blacklistPattern, $name)) {
$obfuscatedCustomVars[$name] = '***';
$result[$name] = '***';
} elseif ($value instanceof stdClass || is_array($value)) {
$obfuscated = $obfuscator($value);
$result[$name] = $value instanceof stdClass ? (object) $obfuscated : $obfuscated;
} else {
$obfuscatedCustomVars[$name] = $value instanceof stdClass || is_array($value)
? $obfuscator($value)
: $value;
$result[$name] = $value;
}
}

return $result;
};
$obfuscator($customvars);
$obfuscatedCustomVars = $obfuscator($customvars);

return $customvars instanceof stdClass ? (object) $obfuscatedCustomVars : $obfuscatedCustomVars;
}
Expand Down

0 comments on commit 78e947a

Please sign in to comment.