File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed
lib/codeql/ruby/frameworks
src/queries/security/cwe-352 Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -297,3 +297,23 @@ class ActionControllerSkipForgeryProtectionCall extends CSRFProtectionSetting::R
297
297
298
298
override boolean getVerificationSetting ( ) { result = false }
299
299
}
300
+
301
+ /**
302
+ * A call to `protect_from_forgery`.
303
+ */
304
+ private class ActionControllerProtectFromForgeryCall extends CSRFProtectionSetting:: Range {
305
+ private ActionControllerContextCall callExpr ;
306
+
307
+ ActionControllerProtectFromForgeryCall ( ) {
308
+ callExpr = this .asExpr ( ) .getExpr ( ) and
309
+ callExpr .getMethodName ( ) = "protect_from_forgery"
310
+ }
311
+
312
+ private string getWithValueText ( ) { result = callExpr .getKeywordArgument ( "with" ) .getValueText ( ) }
313
+
314
+ // Calls without `with: :exception` can allow for bypassing CSRF protection
315
+ // in some scenarios.
316
+ override boolean getVerificationSetting ( ) {
317
+ if this .getWithValueText ( ) = "exception" then result = true else result = false
318
+ }
319
+ }
Original file line number Diff line number Diff line change 50
50
<code >skip_before_action</code >.
51
51
</p >
52
52
53
+ <p >
54
+ Care should be taken when using the Rails
55
+ <code >protect_from_forgery</code > method to prevent CSRF. The default
56
+ behaviour of this method is to null the session when an invalid CSRF token
57
+ is provided. This may not be sufficient to avoid a CSRF vulnerability -
58
+ for example if parts of the session are memoized. Calling
59
+ <code >protect_from_forgery with: :exception</code > can help to avoid this
60
+ by raising an exception on an invalid CSRF token instead.
61
+ </p >
62
+
53
63
</example >
54
64
55
65
<references >
56
66
<li >Wikipedia: <a href =" https://en.wikipedia.org/wiki/Cross-site_request_forgery" >Cross-site request forgery</a ></li >
57
67
<li >OWASP: <a href =" https://owasp.org/www-community/attacks/csrf" >Cross-site request forgery</a ></li >
58
68
<li >Securing Rails Applications: <a href =" https://guides.rubyonrails.org/security.html#cross-site-request-forgery-csrf" >Cross-Site Request Forgery (CSRF)</a ></li >
69
+ <li >Veracode: <a href =" https://www.veracode.com/blog/managing-appsec/when-rails-protectfromforgery-fails" >When Rails' protect_from_forgery Fails</a >.</li >
59
70
</references >
60
71
61
72
</qhelp >
Original file line number Diff line number Diff line change 1
1
/**
2
- * @name CSRF protection disabled
3
- * @description Disabling CSRF protection makes the application vulnerable to
4
- * a Cross-Site Request Forgery (CSRF) attack.
2
+ * @name CSRF protection weakened or disabled
3
+ * @description Disabling or weakening CSRF protection may make the application
4
+ * vulnerable to a Cross-Site Request Forgery (CSRF) attack.
5
5
* @kind problem
6
6
* @problem.severity warning
7
7
* @security-severity 8.8
@@ -16,4 +16,4 @@ import codeql.ruby.Concepts
16
16
17
17
from CSRFProtectionSetting s
18
18
where s .getVerificationSetting ( ) = false
19
- select s , "Potential CSRF vulnerability due to forgery protection being disabled."
19
+ select s , "Potential CSRF vulnerability due to forgery protection being disabled or weakened ."
You can’t perform that action at this time.
0 commit comments