Skip to content

Commit 2e0e9e0

Browse files
authored
Merge pull request #20550 from github/smowton/admin/document-rails-5-csrf
Ruby: Update CSRF protection notes in documentation
2 parents 47b26dd + ff4b97b commit 2e0e9e0

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-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 provide an
65+
empty session rather than raise an exception.
6166
</p>
6267

6368
</example>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
vulnerability - for example if parts of the session are memoized. Calling
4343
<code>protect_from_forgery with: :exception</code> can help to avoid this
4444
by raising an exception on an invalid CSRF token instead.
45+
46+
Note that Rails versions 5 and later
47+
automatically run <code>protect_from_forgery with: :exception</code>
48+
by default, but manually calling <code>protect_from_forgery</code> with
49+
no <code>with</code> argument will downgrade protection to provide an empty
50+
session rather than raise an exception.
4551
</p>
4652
</recommendation>
4753

0 commit comments

Comments
 (0)