summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-04-29 12:45:44 +0200
committerBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2024-05-07 14:54:06 +0200
commit494648dddd36b57c12b31d102b238b413c7d77c1 (patch)
tree113434c7654daa640322af8ad6c7fd1fb77e0420 /lib
parent65e0bc7affd7d76320e69374558f68ec7a7c1fb0 (diff)
downloadnextcloud-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.php12
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 {