Skip to content

Commit

Permalink
fix(session): Do not log fresh/empty session as error
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Nov 7, 2023
1 parent f412c8d commit 63069b6
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/private/Session/CryptoSessionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\ISession;
use OCP\Security\ICrypto;
use OCP\Session\Exceptions\SessionNotAvailableException;
use function json_decode;
use function OCP\Log\logger;

/**
Expand Down Expand Up @@ -80,19 +81,24 @@ public function __destruct() {

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);
}
}
}

Expand Down

0 comments on commit 63069b6

Please sign in to comment.