Upstream Seldaek/monolog state of the touched files before 466b18ff51
This commit is contained in:
1 parent
78b679dd92
commit
fb5cc5f9ee
2 files changed
+2
-41
No files matched your search
@@ -203,9 +203,8 @@ final class RedactingFormatter implements WrappingFormatterInterface
|
|||||||
if (\is_array($data)) {
|
if (\is_array($data)) {
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
if (\is_string($key) && \in_array(strtolower($key), $this->sensitiveKeys, true)) {
|
if (\is_string($key) && \in_array(strtolower($key), $this->sensitiveKeys, true)) {
|
||||||
// the value is masked in the record, but a nested array's leaves can still
|
// no need to recurse, the whole value is masked in the record anyway
|
||||||
// leak elsewhere (e.g. json-encoded by PsrLogMessageProcessor)
|
$this->addSecret($value, $secrets);
|
||||||
$this->collectSensitiveValue($value, $secrets, $depth + 1);
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -240,28 +239,6 @@ final class RedactingFormatter implements WrappingFormatterInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Collects every string leaf nested inside a value under a sensitive key.
|
|
||||||
*
|
|
||||||
* @param list<string> $secrets
|
|
||||||
*/
|
|
||||||
private function collectSensitiveValue(mixed $value, array &$secrets, int $depth): void
|
|
||||||
{
|
|
||||||
if ($depth > self::MAX_DEPTH) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\is_array($value)) {
|
|
||||||
foreach ($value as $item) {
|
|
||||||
$this->collectSensitiveValue($item, $secrets, $depth + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->addSecret($value, $secrets);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reflects the properties of an object matching a #[SensitiveParameter] constructor parameter
|
* Reflects the properties of an object matching a #[SensitiveParameter] constructor parameter
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -243,22 +243,6 @@ class RedactingFormatterTest extends MonologTestCase
|
|||||||
$this->assertStringContainsString('calling api with [REDACTED]', $output);
|
$this->assertStringContainsString('calling api with [REDACTED]', $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRedactsSecretNestedInAnArrayValueAlreadyInterpolatedIntoTheMessage()
|
|
||||||
{
|
|
||||||
// PsrLogMessageProcessor json-encodes array context into the message, so a
|
|
||||||
// secret nested under a sensitive key leaks before this formatter runs.
|
|
||||||
$formatter = new RedactingFormatter(new LineFormatter('%message% %context%', 'Y-m-d'));
|
|
||||||
$processor = new PsrLogMessageProcessor();
|
|
||||||
|
|
||||||
$output = $formatter->format($processor($this->getRecord(
|
|
||||||
message: 'password reset payload: {password}',
|
|
||||||
context: ['password' => ['new' => 'tok-supersecret-value']],
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->assertStringNotContainsString('tok-supersecret-value', $output);
|
|
||||||
$this->assertStringContainsString('[REDACTED]', $output);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRedactsSecretEmbeddedInAnExceptionMessage()
|
public function testRedactsSecretEmbeddedInAnExceptionMessage()
|
||||||
{
|
{
|
||||||
$formatter = new RedactingFormatter(new JsonFormatter());
|
$formatter = new RedactingFormatter(new JsonFormatter());
|
||||||
|
|||||||
Reference in new issue
Block a user