Skip to content

Commit a4031be

Browse files
committed
fix(initializeSession): only log HMAC problem to critical logs if indeed critical
Signed-off-by: Simon L. <szaimen@e.mail.de>
1 parent 46f61ca commit a4031be

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

lib/private/Security/Crypto.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function decrypt(string $authenticatedCiphertext, string $password = ''):
9696
return $this->decryptWithoutSecret($authenticatedCiphertext, $secret);
9797
}
9898
return $this->decryptWithoutSecret($authenticatedCiphertext, $password);
99-
} catch (Exception $e) {
99+
} catch (\RuntimeException | Exception $e) {
100100
if ($password === '') {
101101
// Retry with empty secret as a fallback for instances where the secret might not have been set by accident
102102
return $this->decryptWithoutSecret($authenticatedCiphertext, '');
@@ -159,7 +159,7 @@ private function decryptWithoutSecret(string $authenticatedCiphertext, string $p
159159
}
160160
} else {
161161
if (!hash_equals($this->calculateHMAC($parts[0] . $parts[1], $hmacKey), $hmac)) {
162-
throw new Exception('HMAC does not match.');
162+
throw new \RuntimeException('HMAC does not match.');
163163
}
164164
}
165165

lib/private/Session/CryptoSessionData.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ protected function initializeSession() {
5858
512,
5959
JSON_THROW_ON_ERROR,
6060
);
61+
} catch (\RuntimeException $e) {
62+
// Even though this might be critical in general, we are automatically trying again and will likely succeed.
63+
// We only log to info to not spam the logs with a well-known problem the admin cannot do anything about.
64+
// See https://github.com/nextcloud/server/issues/42157
65+
logger('core')->info('Could not decrypt or decode encrypted session data', [
66+
'exception' => $e,
67+
]);
68+
$this->sessionValues = [];
69+
$this->regenerateId(true, false);
6170
} catch (\Exception $e) {
6271
logger('core')->critical('Could not decrypt or decode encrypted session data', [
6372
'exception' => $e,

0 commit comments

Comments
 (0)