Merge pull request #41318 from nextcloud/fix/session/empty-session-error-logging

fix(session): Do not log fresh/empty session as error
pull/41374/head
Christoph Wurst 2023-11-10 18:55:39 +07:00 committed by GitHub
commit 78d5ec463b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 12 deletions

@ -32,6 +32,7 @@ namespace OC\Session;
use OCP\ISession;
use OCP\Security\ICrypto;
use OCP\Session\Exceptions\SessionNotAvailableException;
use function json_decode;
use function OCP\Log\logger;
/**
@ -80,19 +81,24 @@ class CryptoSessionData implements \ArrayAccess, ISession {
protected function initializeSession() {
$encryptedSessionData = $this->session->get(self::encryptedSessionName) ?: '';
try {
$this->sessionValues = json_decode(
$this->crypto->decrypt($encryptedSessionData, $this->passphrase),
true,
512,
JSON_THROW_ON_ERROR,
);
} catch (\Exception $e) {
logger('core')->critical('Could not decrypt or decode encrypted session data', [
'exception' => $e,
]);
if ($encryptedSessionData === '') {
// Nothing to decrypt
$this->sessionValues = [];
$this->regenerateId(true, false);
} else {
try {
$this->sessionValues = json_decode(
$this->crypto->decrypt($encryptedSessionData, $this->passphrase),
true,
512,
JSON_THROW_ON_ERROR,
);
} catch (\Exception $e) {
logger('core')->critical('Could not decrypt or decode encrypted session data', [
'exception' => $e,
]);
$this->sessionValues = [];
$this->regenerateId(true, false);
}
}
}