Skip to content

Commit 76595ee

Browse files
committed
fix: maskSensitiveData() may mask backtrace data like file
1 parent 36a5f5a commit 76595ee

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -931,11 +931,6 @@
931931
'count' => 1,
932932
'path' => __DIR__ . '/system/Debug/Exceptions.php',
933933
];
934-
$ignoreErrors[] = [
935-
'message' => '#^Method CodeIgniter\\\\Debug\\\\Exceptions\\:\\:maskSensitiveData\\(\\) has no return type specified\\.$#',
936-
'count' => 1,
937-
'path' => __DIR__ . '/system/Debug/Exceptions.php',
938-
];
939934
$ignoreErrors[] = [
940935
'message' => '#^Method CodeIgniter\\\\Debug\\\\Exceptions\\:\\:render\\(\\) has no return type specified\\.$#',
941936
'count' => 1,

system/Debug/Exceptions.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,31 +315,48 @@ protected function collectVars(Throwable $exception, int $statusCode): array
315315
* @return array|object
316316
*/
317317
protected function maskSensitiveData($trace, array $keysToMask, string $path = '')
318+
{
319+
foreach ($trace as $i => $line) {
320+
$trace[$i]['args'] = $this->maskData($line['args'], $this->config->sensitiveDataInTrace);
321+
}
322+
323+
return $trace;
324+
}
325+
326+
/**
327+
* @param array|object $args
328+
*
329+
* @return array|object
330+
*/
331+
private function maskData($args, array $keysToMask, string $path = '')
318332
{
319333
foreach ($keysToMask as $keyToMask) {
320334
$explode = explode('/', $keyToMask);
321335
$index = end($explode);
322336

323337
if (strpos(strrev($path . '/' . $index), strrev($keyToMask)) === 0) {
324-
if (is_array($trace) && array_key_exists($index, $trace)) {
325-
$trace[$index] = '******************';
326-
} elseif (is_object($trace) && property_exists($trace, $index) && isset($trace->{$index})) {
327-
$trace->{$index} = '******************';
338+
if (is_array($args) && array_key_exists($index, $args)) {
339+
$args[$index] = '******************';
340+
} elseif (
341+
is_object($args) && property_exists($args, $index)
342+
&& isset($args->{$index}) && is_scalar($args->{$index})
343+
) {
344+
$args->{$index} = '******************';
328345
}
329346
}
330347
}
331348

332-
if (is_array($trace)) {
333-
foreach ($trace as $pathKey => $subarray) {
334-
$trace[$pathKey] = $this->maskSensitiveData($subarray, $keysToMask, $path . '/' . $pathKey);
349+
if (is_array($args)) {
350+
foreach ($args as $pathKey => $subarray) {
351+
$args[$pathKey] = $this->maskData($subarray, $keysToMask, $path . '/' . $pathKey);
335352
}
336-
} elseif (is_object($trace)) {
337-
foreach ($trace as $pathKey => $subarray) {
338-
$trace->{$pathKey} = $this->maskSensitiveData($subarray, $keysToMask, $path . '/' . $pathKey);
353+
} elseif (is_object($args)) {
354+
foreach ($args as $pathKey => $subarray) {
355+
$args->{$pathKey} = $this->maskData($subarray, $keysToMask, $path . '/' . $pathKey);
339356
}
340357
}
341358

342-
return $trace;
359+
return $args;
343360
}
344361

345362
/**

0 commit comments

Comments
 (0)