feat: add JWT blacklist for logout with TTL cleanup

blacklistJwt() adds token to in-memory blacklist until its natural expiry.
verifyJwt() checks blacklist before signature verification.
Cleanup interval removes expired entries every 10 minutes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-12 23:45:57 +00:00
co-authored by Claude Opus 4.6
parent ca9f5f36e6
commit a96e8922b6
2 changed files with 40 additions and 1 deletions
+14 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, afterEach } from 'vitest'
import { createJwt, verifyJwt } from './jwt.js'
import { createJwt, verifyJwt, blacklistJwt } from './jwt.js'
describe('JWT', () => {
afterEach(() => {
@@ -66,4 +66,17 @@ describe('JWT', () => {
expect(verifyJwt('a.b')).toBeNull()
expect(verifyJwt('a.b.c.d')).toBeNull()
})
it('rejects blacklisted JWT (logout)', () => {
const token = createJwt('pubkey-logout', 'bot-logout')
// Token works before blacklisting
expect(verifyJwt(token)).not.toBeNull()
// Blacklist the token
blacklistJwt(token)
// Token is now rejected
expect(verifyJwt(token)).toBeNull()
})
})