mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 01:30:50 -04:00
fix(logger): Make the handling of SensitiveParameters consistent
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
28c8a46ef9
commit
ca08437967
2 changed files with 22 additions and 1 deletions
|
|
@ -220,7 +220,9 @@ class ExceptionSerializer {
|
|||
private function removeValuesFromArgs($args, $values): array {
|
||||
$workArgs = [];
|
||||
foreach ($args as $arg) {
|
||||
if (in_array($arg, $values, true)) {
|
||||
if (isset($arg['__class__']) && $arg['__class__'] === \SensitiveParameterValue::class) {
|
||||
$arg = self::SENSITIVE_VALUE_PLACEHOLDER;
|
||||
} elseif (in_array($arg, $values, true)) {
|
||||
$arg = self::SENSITIVE_VALUE_PLACEHOLDER;
|
||||
} elseif (is_array($arg)) {
|
||||
$arg = $this->removeValuesFromArgs($arg, $values);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,14 @@ class ExceptionSerializerTest extends TestCase {
|
|||
throw new \Exception('expected custom auth exception');
|
||||
}
|
||||
|
||||
private function usingSensitiveParameterAttribute(
|
||||
string $login,
|
||||
#[\SensitiveParameter]
|
||||
string $parole,
|
||||
): void {
|
||||
throw new \Exception('SensitiveParameter attribute');
|
||||
}
|
||||
|
||||
/**
|
||||
* this test ensures that the serializer does not overwrite referenced
|
||||
* variables. It is crafted after a scenario we experienced: the DAV server
|
||||
|
|
@ -81,4 +89,15 @@ class ExceptionSerializerTest extends TestCase {
|
|||
$this->assertFalse(isset($serializedData['Trace'][0]['args'][1]));
|
||||
}
|
||||
}
|
||||
|
||||
public function testSensitiveParameterAttribute(): void {
|
||||
try {
|
||||
$this->usingSensitiveParameterAttribute('u57474', 'Secret');
|
||||
} catch (\Exception $e) {
|
||||
$serializedData = $this->serializer->serializeException($e);
|
||||
$this->assertSame('usingSensitiveParameterAttribute', $serializedData['Trace'][0]['function']);
|
||||
$this->assertSame('u57474', $serializedData['Trace'][0]['args'][0]);
|
||||
$this->assertSame('*** sensitive parameters replaced ***', $serializedData['Trace'][0]['args'][1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue