Skip to content

Commit

Permalink
Ruby: reduce duplicate alerts for csrf query
Browse files Browse the repository at this point in the history
Only generate an alert on the top-most vulnerable Rails controller in
the controller tree.
  • Loading branch information
hmac committed Oct 12, 2023
1 parent 1fc22d2 commit f31a483
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import codeql.ruby.frameworks.Gemfile

/**
* Holds if a call to `protect_from_forgery` is made in the controller class `definedIn`,
* which is inherited by the controller class `child`.
* which is inherited by the controller class `child`. These classes may be the same.
*/
private predicate protectFromForgeryCall(
ActionControllerClass definedIn, ActionControllerClass child,
Expand All @@ -45,5 +45,7 @@ where
railsPreVersion3()
or
not any(MethodCall m).getMethodName() = ["csrf_meta_tags", "csrf_meta_tag"]
)
) and
// Only generate alerts for the topmost controller in the tree.
not exists(ActionControllerClass parent | c = parent.getAnImmediateDescendent())
select c, "Potential CSRF vulnerability due to forgery protection not being enabled."
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
| railsapp/app/controllers/alternative_root_controller.rb:1:1:3:3 | AlternativeRootController | Potential CSRF vulnerability due to forgery protection not being enabled. |
| railsapp/app/controllers/tags_controller.rb:1:1:2:3 | TagsController | Potential CSRF vulnerability due to forgery protection not being enabled. |

0 comments on commit f31a483

Please sign in to comment.