From bc35deee5ebf3345d5b65e426ff234d8475e6764 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 10 Aug 2022 15:54:51 +0200 Subject: [PATCH] Catch PHP in_array recursion inside exception serializer Signed-off-by: Christoph Wurst --- lib/private/Log/ExceptionSerializer.php | 31 ++++++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/private/Log/ExceptionSerializer.php b/lib/private/Log/ExceptionSerializer.php index aaf6a39235e0e..f19418b3b9ba8 100644 --- a/lib/private/Log/ExceptionSerializer.php +++ b/lib/private/Log/ExceptionSerializer.php @@ -40,6 +40,9 @@ use OCA\Encryption\KeyManager; use OCA\Encryption\Session; use OCP\HintException; +use Throwable; +use function in_array; +use function is_array; class ExceptionSerializer { public const SENSITIVE_VALUE_PLACEHOLDER = '*** sensitive parameters replaced ***'; @@ -210,16 +213,26 @@ private function filterTrace(array $trace) { } private function removeValuesFromArgs($args, $values) { - $workArgs = []; - foreach ($args as $arg) { - if (in_array($arg, $values, true)) { - $arg = self::SENSITIVE_VALUE_PLACEHOLDER; - } elseif (is_array($arg)) { - $arg = $this->removeValuesFromArgs($arg, $values); + return array_map(function($arg) use ($values) { + // Sensitive? + try { + if (in_array($arg, $values, true)) { + return self::SENSITIVE_VALUE_PLACEHOLDER; + } + } catch (Throwable $e) { + // In very rare cases PHP can't run in_array on the args because + // of a recursive structure. In that case we fall back to + // assuming the argument could be sensitive + return self::SENSITIVE_VALUE_PLACEHOLDER; } - $workArgs[] = $arg; - } - return $workArgs; + + // Array? + if (is_array($arg)) { + return $this->removeValuesFromArgs($arg, $values); + } + + return $arg; + }, $args); } private function encodeTrace($trace) {