Skip to content

Make Devise::FailureApp commit the CSRF token on Rails 7.1+.#5851

Open
augustocbx wants to merge 1 commit into
heartcombo:mainfrom
augustocbx:fix-failure-app-csrf-token-storage
Open

Make Devise::FailureApp commit the CSRF token on Rails 7.1+.#5851
augustocbx wants to merge 1 commit into
heartcombo:mainfrom
augustocbx:fix-failure-app-csrf-token-storage

Conversation

@augustocbx

Copy link
Copy Markdown
Contributor

Rails 7.1 changed CSRF token storage (rails/rails#44283) so the deferred token is committed to the session at the end of the request through the controller instance, which must respond to commit_csrf_token. Devise::FailureApp extends ActionController::Metal (not ActionController::Base) and becomes that controller instance when :warden is thrown, so on an authentication failure the deferred CSRF token — and the session itself — were silently dropped (no session cookie returned).

This includes ActionController::RequestForgeryProtection in Devise::FailureApp so it provides commit_csrf_token, restoring CSRF token and session persistence on auth failure. Only FailureApp needs this, since real controllers already get it from ActionController::Base.

Fixes #5698.

@augustocbx augustocbx force-pushed the fix-failure-app-csrf-token-storage branch from ed9d010 to 79ce74e Compare June 11, 2026 05:04
@augustocbx augustocbx force-pushed the fix-failure-app-csrf-token-storage branch from 79ce74e to dc25c69 Compare June 11, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Devise::FailureApp is not compatible with Rails 7.1 csrf_token_storage

1 participant