diff options
author | Joas Schilling <coding@schilljs.com> | 2025-01-03 10:04:51 +0100 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2025-01-03 11:12:48 +0000 |
commit | b9493cc12d3753811d1715d055b40ad0e353082f (patch) | |
tree | d7d96f6cd92c4f7934b9d30aa7db0125f2b63de0 /lib | |
parent | 2d77570e1e6768e240590ff90c8c8b90fb1d557b (diff) | |
download | nextcloud-server-backport/50026/stable30.tar.gz nextcloud-server-backport/50026/stable30.zip |
fix(logger): Prevent infinite recursion with log.condition => matchesbackport/50026/stable30
When we need to check the log condition for a user matches,
there is a risk that something on the way checks the log level
and would result in an infinite loop.
So we simply check if it's a nested call and use the default
warning level in that case.
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Log.php | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php index 4fce0436707..e2b732473c2 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -37,6 +37,7 @@ use function strtr; class Log implements ILogger, IDataLogger { private ?bool $logConditionSatisfied = null; private ?IEventDispatcher $eventDispatcher = null; + private int $nestingLevel = 0; public function __construct( private IWriter $logger, @@ -196,6 +197,11 @@ class Log implements ILogger, IDataLogger { } public function getLogLevel(array $context, string $message): int { + if ($this->nestingLevel > 1) { + return ILogger::WARN; + } + + $this->nestingLevel++; /** * @psalm-var array{ * shared_secret?: string, @@ -246,6 +252,7 @@ class Log implements ILogger, IDataLogger { // if log condition is satisfied change the required log level to DEBUG if ($this->logConditionSatisfied) { + $this->nestingLevel--; return ILogger::DEBUG; } @@ -260,6 +267,7 @@ class Log implements ILogger, IDataLogger { * once this is met -> change the required log level to debug */ if (in_array($context['app'], $logCondition['apps'] ?? [], true)) { + $this->nestingLevel--; return ILogger::DEBUG; } } @@ -272,6 +280,7 @@ class Log implements ILogger, IDataLogger { // Invalid configuration, warn the user and fall back to default level of WARN error_log('Nextcloud configuration: "loglevel" is not a valid integer'); + $this->nestingLevel--; return ILogger::WARN; } @@ -285,12 +294,15 @@ class Log implements ILogger, IDataLogger { if (!isset($option['apps']) && !isset($option['loglevel']) && !isset($option['message'])) { /* Only user and/or secret are listed as conditions, we can cache the result for the rest of the request */ $this->logConditionSatisfied = true; + $this->nestingLevel--; return ILogger::DEBUG; } + $this->nestingLevel--; return $option['loglevel'] ?? ILogger::DEBUG; } } + $this->nestingLevel--; return ILogger::WARN; } |