Skip to content

Commit 18c5cb1

Browse files
authored
Ruby: Update CSRF protection notes in documentation
Autofix is confused about how the `protect_from_forgery` method works in Rails >= 5: GPT-5 says: > In modern Rails versions (>=5, including 6 and 7 which this gem permits), ActionController::Base already enables CSRF protection by default with the `:exception` strategy; an explicit call to `protect_from_forgery` without options does not weaken security. This is false: manual testing confirms that it actually does downgrade from `:exception` to `:null-session` behaviour when a manual call is made. I can't find any authoritative source showing this gotcha, so I can see how the AI is confused and how humans might also struggle to verify the truth.
1 parent b52fff2 commit 18c5cb1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ruby/ql/src/queries/security/cwe-352/CSRFProtectionDisabled.qhelp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
for example if parts of the session are memoized. Calling
5959
<code>protect_from_forgery with: :exception</code> can help to avoid this
6060
by raising an exception on an invalid CSRF token instead.
61+
Note this remains true even in Rails version 5 and later: these versions
62+
automatically run <code>protect_from_forgery with: :exception</code>
63+
by default, but manually calling <code>protect_from_forgery</code> with
64+
no <code>with</code> argument will still downgrade protection to null the
65+
session rather than raise an exception.
6166
</p>
6267

6368
</example>

0 commit comments

Comments
 (0)