From bf5487482d545e04359ee7f97fa375bd77bb3078 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 16 Jun 2022 13:30:52 +0200 Subject: [PATCH] fix overwriting original vars when logging Signed-off-by: Arthur Schiwon --- lib/private/Log/ExceptionSerializer.php | 6 ++++-- tests/lib/Log/ExceptionSerializerTest.php | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/private/Log/ExceptionSerializer.php b/lib/private/Log/ExceptionSerializer.php index fb63ddf0a0e..fc9e4cc1bd0 100644 --- a/lib/private/Log/ExceptionSerializer.php +++ b/lib/private/Log/ExceptionSerializer.php @@ -208,14 +208,16 @@ class ExceptionSerializer { } private function removeValuesFromArgs($args, $values) { - foreach ($args as &$arg) { + $workArgs = []; + foreach ($args as $arg) { if (in_array($arg, $values, true)) { $arg = '*** sensitive parameter replaced ***'; } elseif (is_array($arg)) { $arg = $this->removeValuesFromArgs($arg, $values); } + $workArgs[] = $arg; } - return $args; + return $workArgs; } private function encodeTrace($trace) { diff --git a/tests/lib/Log/ExceptionSerializerTest.php b/tests/lib/Log/ExceptionSerializerTest.php index eede081bda3..02d91b726e2 100644 --- a/tests/lib/Log/ExceptionSerializerTest.php +++ b/tests/lib/Log/ExceptionSerializerTest.php @@ -60,8 +60,9 @@ class ExceptionSerializerTest extends TestCase { $secret = ['Secret']; $this->emit([&$secret]); } catch (\Exception $e) { - $this->serializer->serializeException($e); + $serializedData = $this->serializer->serializeException($e); $this->assertSame(['Secret'], $secret); + $this->assertSame('*** sensitive parameters replaced ***', $serializedData['Trace'][0]['args'][0]); } } }