Skip to content

Commit 32b775f

Browse files
committed
Ruby: reduce duplicate alerts for csrf query
Only generate an alert on the top-most vulnerable Rails controller in the controller tree.
1 parent 1fbf177 commit 32b775f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import codeql.ruby.frameworks.Gemfile
1818

1919
/**
2020
* Holds if a call to `protect_from_forgery` is made in the controller class `definedIn`,
21-
* which is inherited by the controller class `child`.
21+
* which is inherited by the controller class `child`. These classes may be the same.
2222
*/
2323
private predicate protectFromForgeryCall(
2424
ActionControllerClass definedIn, ActionControllerClass child,
@@ -45,5 +45,7 @@ where
4545
railsPreVersion3()
4646
or
4747
not any(MethodCall m).getMethodName() = ["csrf_meta_tags", "csrf_meta_tag"]
48-
)
48+
) and
49+
// Only generate alerts for the topmost controller in the tree.
50+
not exists(ActionControllerClass parent | c = parent.getAnImmediateDescendent())
4951
select c, "Potential CSRF vulnerability due to forgery protection not being enabled."
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
| railsapp/app/controllers/alternative_root_controller.rb:1:1:3:3 | AlternativeRootController | Potential CSRF vulnerability due to forgery protection not being enabled. |
2-
| railsapp/app/controllers/tags_controller.rb:1:1:2:3 | TagsController | Potential CSRF vulnerability due to forgery protection not being enabled. |

0 commit comments

Comments
 (0)