diff options
author | Joas Schilling <coding@schilljs.com> | 2024-04-29 12:45:44 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-04-29 12:45:44 +0200 |
commit | bc4a102f52cba04e437532f18b3538b6856a3084 (patch) | |
tree | 809434e7a68b1c33473b5623b072dfcb671fe05a /lib/private/Authentication | |
parent | 2c059dd606f923e5fd689815a09a263bed1c25fd (diff) | |
download | nextcloud-server-bc4a102f52cba04e437532f18b3538b6856a3084.tar.gz nextcloud-server-bc4a102f52cba04e437532f18b3538b6856a3084.zip |
fix(session): Avoid race condition for cache::get() vs. cache::hasKey()
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Authentication')
-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 48a23b61e0b..3a15ba006d4 100644 --- a/lib/private/Authentication/Token/PublicKeyTokenProvider.php +++ b/lib/private/Authentication/Token/PublicKeyTokenProvider.php @@ -192,11 +192,11 @@ class PublicKeyTokenProvider implements IProvider { */ private function getTokenFromCache(string $tokenHash): ?PublicKeyToken { $serializedToken = $this->cache->get($tokenHash); - if ($serializedToken === null) { - 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; } @@ -211,9 +211,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): OCPIToken { |