Use protect_from_forgery with: :exception#6926
Merged
compwron merged 1 commit intorubyforgood:mainfrom May 5, 2026
Merged
Conversation
CodeQL alert rubyforgood#60 (rb/csrf-protection-disabled, CWE-352): calling protect_from_forgery with no with: argument downgrades the failure mode to with: :null_session, weaker than the Rails 5+ default of with: :exception that ActionController::Base would otherwise apply. Make the strategy explicit so the call no longer weakens the default, matching option 2 from the issue (more self-documenting than removing the call entirely).
compwron
approved these changes
May 5, 2026
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.
What github issue is this PR for, if any?
Resolves #6920
What changed, and why?
app/controllers/application_controller.rb:7was callingprotect_from_forgerywith nowith:argument, which downgrades the failure mode towith: :null_session-- weaker than the Rails 5+ default ofwith: :exceptionthatActionController::Baseapplies on its own. CodeQL flagged this as alert #60 (rb/csrf-protection-disabled, CWE-352).This PR takes option 2 from the issue: keep the call but make the strategy explicit. That resolves the alert while leaving a self-documenting CSRF setting in place rather than relying on the framework default.
How is this tested? (please write rspec and jest tests!) 💖💪
No new spec is added. The change is the recommended fix from a CodeQL static-analysis alert and brings the call in line with the Rails 5+ default
ActionController::Basewould otherwise apply, so existing controller / request / system specs continue to exercise the CSRF flow with the same effective strategy. CodeQL alert #60 should auto-close after the next scan onmain.Screenshots please :)
n/a -- this is a one-line
application_controller.rbchange with no UI surface.