Skip to content

Commit

Permalink
Merge pull request #41006 from nextcloud/backport/40879/stable27
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv committed Feb 22, 2024
2 parents fb0a2d5 + bcd7d59 commit 87fc748
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/private/Session/CryptoSessionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
use OCP\ISession;
use OCP\Security\ICrypto;
use OCP\Session\Exceptions\SessionNotAvailableException;
use function json_decode;
use function OCP\Log\logger;

/**
* Class CryptoSessionData
Expand Down Expand Up @@ -79,14 +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
);
} catch (\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 87fc748

Please sign in to comment.