Skip to content

feat(auth): graceful CSRF-failure retry on login - #3174

Open
FrankApiyo wants to merge 1 commit into
mainfrom
feat/csrf-failure-retry
Open

feat(auth): graceful CSRF-failure retry on login#3174
FrankApiyo wants to merge 1 commit into
mainfrom
feat/csrf-failure-retry

Conversation

@FrankApiyo

@FrankApiyo FrankApiyo commented Jul 15, 2026

Copy link
Copy Markdown
Member

Changes / Features implemented

A login POST that fails CSRF validation (stale or rotated token — e.g. a login tab left open across a deploy) now redirects back to a fresh login page with the safe next preserved, instead of dead-ending on Django's 403 page.

Steps taken to verify this change does what is intended

  • Unit tests: redirect target, next safety (unsafe values dropped), non-login paths keep the default 403

Side effects of implementing this change

  • Only the login path gets the redirect; every other view keeps Django's default CSRF-failure behavior

Before submitting this PR for review, please make sure you have:

  • Included tests
  • Updated documentation

A CSRF failure on the login page is almost always a stale/rotated token
(old tab, back button, cookie rotation), not an attack — but Django's
default response is a dead-end 403 that strands the user. Add a
CSRF_FAILURE_VIEW that sends a failed login POST back to a fresh login
(new token) so the user can simply retry, preserving a safe ?next= so a
brokered OIDC flow continues. Non-login CSRF failures keep the default
403, so genuine cross-site API POSTs are not masked.
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