Skip to content

fix(users): CSRF-protect browser auth requests; logout retires the browser session - #832

Merged
antosubash merged 11 commits into
mainfrom
fix/s03-login-csrf-logout
Nov 5, 2026
Merged

antosubash merged 11 commits into
mainfrom
fix/s03-login-csrf-logout

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Hardening for the users module's local auth.

Browser auth requests

  • Anonymous auth pages (login, register, forgot/reset password, verify, invite accept) pass a session-bound csrfToken prop; the shared typed API client sends it as X-CSRF-Token.
  • Browser requests to the session-setting auth routes (password and demo sign-in, register, forgot/reset password, verify, invite accept, API logout) must echo that token whenever browser signals are present (Origin, Referer, Sec-Fetch-Site). Sec-Fetch-Site: cross-site is refused outright. Clients without browser headers (scripts, the e2e harness) keep working.
  • No Origin-vs-base_url comparison, so deployments behind a TLS-terminating proxy are unaffected.
  • The bearer-token routes (/api/users/auth/token*) set no cookie and touch no session, so they need no token: native clients and CORS-enabled cross-origin clients can use them.
  • The framework CSRF test that pinned "anonymous pages carry no token" now probes a page that only gets the shared props; auth pages carry their own token deliberately.

Logout

  • Users sign-in now mints a per-browser session id (SESSION_ID_KEY). Logout records it in users_revoked_session (migration e805a1b2c3d4, users trunk) until the session's own deadline, idempotently (ON CONFLICT DO NOTHING), and publishes an invalidation after commit. The provider refuses a retired id through the existing session-version cache, so a copied cookie stops working while other devices stay signed in.
  • Sessions minted before this release have no id and keep the previous behaviour until they expire or sign in again (documented).

Behaviour changes are marked in CHANGELOG (Unreleased → Security) and docs/modules/users.md.

Pipeline: /optimize (1 commit), review passes (correctness + maintainability) with triage kept locally.
Local CI: make lint ✓ · make test-py (8 workers) 7887 passed ✓ · make test-js ✓ · make migrations-roundtrip-pg ✓ (run on a fresh database).

Note: migration e805a1b2c3d4 and the background-tasks perf PR's c5d8e2f1a903 both revise e731a1b2c3d4; whichever merges second re-points its down_revision.

https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-05T16:13:31.769222Z feb328d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 05a32cd
Status: ✅  Deploy successful!
Preview URL: https://1ea649f7.simple-module-python.pages.dev
Branch Preview URL: https://fix-s03-login-csrf-logout.simple-module-python.pages.dev

View logs

# Conflicts:
#	CHANGELOG.md
#	host/tests/test_migration_graph.py
@antosubash
antosubash merged commit 7704e40 into main Nov 5, 2026
17 checks passed
@antosubash
antosubash deleted the fix/s03-login-csrf-logout branch November 5, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant