diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2024-05-06 16:30:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-06 16:30:19 +0200 |
commit | 88e871f6ce9d5b0910079ea612a69a5098b3001c (patch) | |
tree | a5ee2a419fec2819a71207ef281b5fbf94425cda | |
parent | 137d4617cb153db81b541b1dc98c1f33b5cdcd30 (diff) | |
parent | 487dfb62d321979f7a5233db710b51198decd7a9 (diff) | |
download | nextcloud-server-88e871f6ce9d5b0910079ea612a69a5098b3001c.tar.gz nextcloud-server-88e871f6ce9d5b0910079ea612a69a5098b3001c.zip |
Merge pull request #45192 from nextcloud/backport/45093/stable29
[stable29] fix(session): Avoid race condition for cache::get() vs. cache::hasKey()
-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 { |