diff options
author | Joas Schilling <coding@schilljs.com> | 2024-04-29 12:45:44 +0200 |
---|---|---|
committer | Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | 2024-05-07 14:54:06 +0200 |
commit | 494648dddd36b57c12b31d102b238b413c7d77c1 (patch) | |
tree | 113434c7654daa640322af8ad6c7fd1fb77e0420 /lib | |
parent | 65e0bc7affd7d76320e69374558f68ec7a7c1fb0 (diff) | |
download | nextcloud-server-494648dddd36b57c12b31d102b238b413c7d77c1.tar.gz nextcloud-server-494648dddd36b57c12b31d102b238b413c7d77c1.zip |
fix(session): Avoid race condition for cache::get() vs. cache::hasKey()
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Authentication/Token/PublicKeyTokenProvider.php | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/private/Authentication/Token/PublicKeyTokenProvider.php b/lib/private/Authentication/Token/PublicKeyTokenProvider.php index 7a5e7f6fd5d..bab025973b9 100644 --- a/lib/private/Authentication/Token/PublicKeyTokenProvider.php +++ b/lib/private/Authentication/Token/PublicKeyTokenProvider.php @@ -189,11 +189,11 @@ class PublicKeyTokenProvider implements IProvider { */ private function getTokenFromCache(string $tokenHash): ?PublicKeyToken { $serializedToken = $this->cache->get($tokenHash); - if (null === $serializedToken) { - if ($this->cache->hasKey($tokenHash)) { - throw new InvalidTokenException('Token does not exist: ' . $tokenHash); - } + if ($serializedToken === false) { + throw new InvalidTokenException('Token does not exist: ' . $tokenHash); + } + if ($serializedToken === null) { return null; } @@ -208,9 +208,9 @@ class PublicKeyTokenProvider implements IProvider { $this->cache->set($token->getToken(), serialize($token), self::TOKEN_CACHE_TTL); } - private function cacheInvalidHash(string $tokenHash) { + private function cacheInvalidHash(string $tokenHash): void { // Invalid entries can be kept longer in cache since it’s unlikely to reuse them - $this->cache->set($tokenHash, null, self::TOKEN_CACHE_TTL * 2); + $this->cache->set($tokenHash, false, self::TOKEN_CACHE_TTL * 2); } public function getTokenById(int $tokenId): IToken { |