Skip to content

Commit eca451e

Browse files
authored
Merge pull request #21101 from hvitved/ruby/fix-bad-join
Ruby: Fix bad join
2 parents 5359b3d + 3583394 commit eca451e

File tree

1 file changed

+16
-9
lines changed
  • ruby/ql/lib/codeql/ruby/frameworks/actioncontroller

1 file changed

+16
-9
lines changed

ruby/ql/lib/codeql/ruby/frameworks/actioncontroller/Filters.qll

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,35 @@ module Filters {
5555
private class FilterCall extends MethodCallCfgNode {
5656
private FilterKind kind;
5757

58+
pragma[nomagic]
5859
FilterCall() {
5960
this.getExpr().getEnclosingModule() = any(ActionControllerClass c).getADeclaration() and
6061
this.getMethodName() = ["", "prepend_", "append_", "skip_"] + kind + "_action"
6162
}
6263

6364
FilterKind getKind() { result = kind }
6465

66+
pragma[nomagic]
67+
private ActionControllerActionMethod getAnActionCand(string name) {
68+
result = getADescendentAction(this) and
69+
name = result.getName() and
70+
// A filter cannot apply to another filter
71+
not result = any(Filter f).getFilterCallable() and
72+
// Only include routable actions. This can exclude valid actions if we can't parse the `routes.rb` file fully.
73+
exists(result.getARoute())
74+
}
75+
6576
/**
6677
* Gets an action which this filter is applied to.
6778
*/
79+
pragma[nomagic]
6880
ActionControllerActionMethod getAnAction() {
69-
// A filter cannot apply to another filter
70-
result != any(Filter f).getFilterCallable() and
71-
// Only include routable actions. This can exclude valid actions if we can't parse the `routes.rb` file fully.
72-
exists(result.getARoute()) and
73-
(
74-
result.getName() = this.getOnlyArgument()
81+
exists(string name | result = this.getAnActionCand(name) |
82+
name = this.getOnlyArgument()
7583
or
7684
not exists(this.getOnlyArgument()) and
77-
forall(string except | except = this.getExceptArgument() | result.getName() != except)
78-
) and
79-
result = getADescendentAction(this)
85+
forall(string except | except = this.getExceptArgument() | name != except)
86+
)
8087
}
8188

8289
private string getOnlyArgument() {

0 commit comments

Comments
 (0)