mirror of
https://github.com/github/codeql.git
synced 2026-04-21 23:14:03 +02:00
Ruby: reduce duplicate alerts for csrf query
Only generate an alert on the top-most vulnerable Rails controller in the controller tree.
This commit is contained in:
@@ -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,
|
||||
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user