Skip to content

Commit 773291e

Browse files
committed
Put exprNodeReturnedFrom predicate in DataFlowDispatch.qll
1 parent e80faa0 commit 773291e

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,16 @@ predicate mayBenefitFromCallContext(DataFlowCall call, Callable c) { none() }
314314
* restricted to those `call`s for which a context might make a difference.
315315
*/
316316
DataFlowCallable viableImplInCallContext(DataFlowCall call, DataFlowCall ctx) { none() }
317+
318+
/**
319+
* Holds if `e` is an `ExprNode` that may be returned by a call to `c`.
320+
*/
321+
predicate exprNodeReturnedFrom(DataFlow::ExprNode e, DataFlowCallable c) {
322+
exists(ReturnNode r |
323+
r.getEnclosingCallable() = c and
324+
(
325+
r.(ExplicitReturnNode).getReturningNode().getReturnedValueNode() = e.asExpr() or
326+
r.(ExprReturnNode) = e
327+
)
328+
)
329+
}

ql/lib/codeql/ruby/dataflow/internal/DataFlowImpl.qll

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4552,13 +4552,3 @@ private predicate revPartialFlow(
45524552
sink.isRevSink() and
45534553
node.getASuccessor+() = sink
45544554
}
4555-
4556-
/**
4557-
* Holds if `n` is a return node from callable `c`.
4558-
*/
4559-
predicate nodeReturnedFrom(ReturnNodeExt n, DataFlowCallable c) {
4560-
exists(RetNodeEx ret |
4561-
n = ret.asNode() and
4562-
c = ret.getReturnPosition().getCallable()
4563-
)
4564-
}

ql/lib/codeql/ruby/security/ReflectedXSSCustomizations.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ private import codeql.ruby.frameworks.ActionController
77
private import codeql.ruby.frameworks.ActionView
88
private import codeql.ruby.dataflow.RemoteFlowSources
99
private import codeql.ruby.dataflow.BarrierGuards
10+
import codeql.ruby.dataflow.internal.DataFlowDispatch
1011
private import codeql.ruby.typetracking.TypeTracker
1112

1213
/**
@@ -190,8 +191,9 @@ module ReflectedXSS {
190191
template = node2.getLocation().getFile() and
191192
helperMethod.getName() = helperMethodCall.getExpr().getMethodName() and
192193
helperMethod.getControllerClass() = getAssociatedControllerClass(template) and
193-
// `node1` is a returned value
194-
DataFlow::nodeReturnedFrom(node1, helperMethod) and
194+
// `node1` is an expr node that may be returned by the helper method
195+
exprNodeReturnedFrom(node1, helperMethod) and
196+
// `node2` is a call to the helper method
195197
node2.asExpr() = helperMethodCall
196198
)
197199
}

ql/test/query-tests/security/cwe-079/ReflectedXSS.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
edges
2-
| app/controllers/foo/bars_controller.rb:9:5:9:29 | return : | app/views/foo/bars/show.html.erb:47:5:47:13 | call to user_name |
3-
| app/controllers/foo/bars_controller.rb:9:12:9:17 | call to params : | app/controllers/foo/bars_controller.rb:9:5:9:29 | return : |
2+
| app/controllers/foo/bars_controller.rb:9:12:9:17 | call to params : | app/controllers/foo/bars_controller.rb:9:12:9:29 | ...[...] : |
3+
| app/controllers/foo/bars_controller.rb:9:12:9:29 | ...[...] : | app/views/foo/bars/show.html.erb:47:5:47:13 | call to user_name |
44
| app/controllers/foo/bars_controller.rb:13:5:13:37 | ... = ... : | app/views/foo/bars/show.html.erb:51:5:51:18 | call to user_name_memo |
55
| app/controllers/foo/bars_controller.rb:13:20:13:25 | call to params : | app/controllers/foo/bars_controller.rb:13:5:13:37 | ... = ... : |
66
| app/controllers/foo/bars_controller.rb:17:21:17:26 | call to params : | app/controllers/foo/bars_controller.rb:17:21:17:36 | ...[...] : |
@@ -19,8 +19,8 @@ edges
1919
| app/views/foo/bars/show.html.erb:54:29:54:34 | call to params : | app/views/foo/bars/show.html.erb:54:29:54:44 | ...[...] |
2020
| app/views/foo/bars/show.html.erb:57:13:57:18 | call to params : | app/views/foo/bars/show.html.erb:57:13:57:28 | ...[...] |
2121
nodes
22-
| app/controllers/foo/bars_controller.rb:9:5:9:29 | return : | semmle.label | return : |
2322
| app/controllers/foo/bars_controller.rb:9:12:9:17 | call to params : | semmle.label | call to params : |
23+
| app/controllers/foo/bars_controller.rb:9:12:9:29 | ...[...] : | semmle.label | ...[...] : |
2424
| app/controllers/foo/bars_controller.rb:13:5:13:37 | ... = ... : | semmle.label | ... = ... : |
2525
| app/controllers/foo/bars_controller.rb:13:20:13:25 | call to params : | semmle.label | call to params : |
2626
| app/controllers/foo/bars_controller.rb:17:21:17:26 | call to params : | semmle.label | call to params : |

0 commit comments

Comments
 (0)