security: AuthGuard cache max size — eviction FIFO 1000 entries

This commit is contained in:
2026-04-05 07:49:56 +02:00
parent 7b7f2ac8e7
commit 2e9e438baa

View File

@@ -12,6 +12,7 @@ interface CacheEntry {
}
const TOKEN_CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
const MAX_CACHE_SIZE = 1000;
@Injectable()
export class AuthGuard implements CanActivate {
@@ -49,6 +50,10 @@ export class AuthGuard implements CanActivate {
const user = await this.introspect(token);
if (user) {
if (this.cache.size >= MAX_CACHE_SIZE) {
const oldest = this.cache.keys().next().value;
if (oldest) this.cache.delete(oldest);
}
this.cache.set(token, {
user,
expiresAt: Date.now() + TOKEN_CACHE_TTL_MS,