Repository navigation
fix(auth): JWT revocation on logout (#187) - #1384
Merged
Merged
Conversation
Pentest 3.3.4: 7-day JWTs had no server-side revocation — an exfiltrated token survived logout/password change for the full token life; there was no logout endpoint at all. - Every access token now carries a random `jti` (create_access_token). - New `POST /api/auth/logout` blacklists the caller's `jti` in Redis with a TTL = the token's remaining life (self-expiring, no sweep). Idempotent; MCP-key callers are a no-op (keys revoke via key management). - get_current_user, decode_token (WS), and /api/auth/validate (nginx) all reject a revoked jti. - Frontend store.logout() calls the endpoint best-effort before clearing local state. Fail-open by design (Redis down or a legacy no-jti token → not revoked), so the check can never lock out a valid session; backend restart still rotates SECRET_KEY. Token-lifetime reduction + refresh tokens left as a separate issue. Related to #187 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
vybe
approved these changes
Jun 30, 2026
vybe
left a comment
Contributor
There was a problem hiding this comment.
/validate-pr: APPROVE. JWT revocation on logout (pentest 3.3.4). jti blacklist in Redis (self-expiring TTL), enforced in get_current_user/decode_token//api/auth/validate; fail-open by design. Strong named regression test test_187_jwt_revocation.py (6 tests, all call-sites). Architecture doc updated. Security clean, mergeable, checks green. Note: 'Related to #187' not a closing keyword — bumping #187 to status-in-dev manually.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the pentest 3.3.4 gap: 7-day JWTs had no server-side revocation and there was no logout endpoint — an exfiltrated token kept working through logout / password change for its full life.
jti(create_access_token).POST /api/auth/logoutblacklists the caller'sjtiin Redis with TTL = the token's remaining life (self-expiring, no sweep). Idempotent; MCP-key callers are a no-op.get_current_user,decode_token(WebSocket), and/api/auth/validate(nginx auth_request) all reject a revokedjti.store.logout()calls the endpoint best-effort before clearing local state.Fail-open by design — Redis down or a legacy no-
jtitoken → treated as not revoked, so the check can never lock out a valid session; a backend restart still rotatesSECRET_KEYand invalidates everything.Out of scope (deferred, separate issue)
Reducing
ACCESS_TOKEN_EXPIRE_MINUTES(7d) + a refresh-token flow — a larger UX change. This PR delivers the revocation mechanism the issue's core asks for.Changes
src/backend/dependencies.py—jticlaim,revoke_token_jti/is_token_revoked(fail-open Redis), revocation checks inget_current_user+decode_tokensrc/backend/routers/auth.py—POST /api/auth/logout;jticheck in/api/auth/validatesrc/frontend/src/stores/auth.js— asynclogout()calls the revoke endpoint firstdocs/memory/architecture.md,tests/unit/test_187_jwt_revocation.pyTest Plan
pytest tests/unit/test_187_jwt_revocation.py— 6 pass (jti minted, revoke→revoked, TTL ≤ token life, past-exp no-op, fail-open on no-jti + Redis-down)/api/users/me200 →POST /api/auth/logout200 → same token/api/users/me401 AND/api/auth/validate401test_connector_authgreen)Related to #187 (epic #1054 Security Hardening)