feat: enterprise-grade auth -- HttpOnly cookie sessions, CSRF, lockout, session limits#1102
Merged
feat: enterprise-grade auth -- HttpOnly cookie sessions, CSRF, lockout, session limits#1102
Conversation
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
Enterprise-grade auth hardening for multi-user deployments. Replaces sessionStorage JWT tokens with HttpOnly cookie sessions, adds CSRF protection, concurrent session limits, account lockout, and refresh token infrastructure.
Backend
Set-Cookie: session=<JWT>; HttpOnly; Secure; SameSite=Strictinstead of returning JWT in response body.CookieSessionResponsereplacesTokenResponseX-CSRF-Tokenheader againstcsrf_tokencookie on mutating requests. Skips API key requests (no cookie = no CSRF risk). Exempt paths for login/setupmax_concurrent_sessionsconfig (default 5),enforce_session_limit()revokes oldest sessions on exceedLockoutStore-- tracks failed login attempts per username, enforces temp lockout after threshold (default 10 in 15 min), timing-safe dummy hash on locked accounts,load_locked()restores state after restartRefreshStorewith HMAC-SHA256 hashed tokens, single-useconsumeviaUPDATE...RETURNING(no TOCTOU), replay detection, session/user revocation cascadeClear-Site-Data: "cookies"headerNotBlankStrvalidation, cross-field validatorsFrontend
auth_tokenin sessionStorage, no expiry timer, noAuthorizationheader injectionauthStatus: 'unknown' | 'authenticated' | 'unauthenticated'replaces!!tokencheck.checkSession()calls/auth/meon page loadcsrf_tokencookie, attachesX-CSRF-Tokenheader on POST/PUT/PATCH/DELETEwithCredentials: trueon Axios client +credentials: 'include'on SSE fetchlistSessions(scope),revokeSession(id), asynclogout()Test coverage
test_cookies.py,test_csrf.py,test_lockout_store.py,test_refresh_store.pytest_middleware.py,test_controller.py,test_config.py,test_session_store.py,test_app.py,test_errors.py,test_migrations.py,test_ws.py+ 8 frontend test filesReview coverage
Pre-reviewed by 11 agents, 28 findings addressed:
Documentation
docs/security.mdupdated with new threat model (HttpOnly cookies, CSRF, lockout, refresh tokens, concurrent sessions)CLAUDE.mdpackage structure updated with new auth modulesdocs/design/operations.mdauth endpoint description updatedTest plan
Closes #1068