Skip to content

Commit 8a3e255

Browse files
committed
remove FPs in rb/stored-xss from spurious sources
1 parent e47e20c commit 8a3e255

File tree

2 files changed

+10
-9
lines changed
  • ruby/ql

2 files changed

+10
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,13 @@ private module OrmTracking {
339339

340340
override predicate isSource(DataFlow2::Node source) { source instanceof OrmInstantiation }
341341

342-
// Select any call node and narrow down later
343-
override predicate isSink(DataFlow2::Node sink) { sink instanceof DataFlow2::CallNode }
342+
// Select any call receiver and narrow down later
343+
override predicate isSink(DataFlow2::Node sink) {
344+
sink = any(DataFlow2::CallNode c).getReceiver()
345+
}
344346

345347
override predicate isAdditionalFlowStep(DataFlow2::Node node1, DataFlow2::Node node2) {
346348
Shared::isAdditionalXssFlowStep(node1, node2)
347-
or
348-
// Propagate flow through arbitrary method calls
349-
node2.(DataFlow2::CallNode).getReceiver() = node1
350349
}
351350
}
352351
}
@@ -379,10 +378,9 @@ module StoredXss {
379378

380379
private class OrmFieldAsSource extends Source instanceof DataFlow2::CallNode {
381380
OrmFieldAsSource() {
382-
exists(OrmTracking::Configuration subConfig, DataFlow2::CallNode subSrc, MethodCall call |
383-
subConfig.hasFlow(subSrc, this) and
384-
call = this.asExpr().getExpr() and
385-
subSrc.(OrmInstantiation).methodCallMayAccessField(call.getMethodName())
381+
exists(OrmTracking::Configuration subConfig, DataFlow2::CallNode subSrc |
382+
subConfig.hasFlow(subSrc, this.getReceiver()) and
383+
subSrc.(OrmInstantiation).methodCallMayAccessField(this.getMethodName())
386384
)
387385
}
388386
}

ruby/ql/test/query-tests/security/cwe-079/app/views/foo/stores/show.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@
8181

8282
<%# BAD: Indirect to a database value without escaping %>
8383
<%= @other_user_raw_name.html_safe %>
84+
85+
<%# GOOD: The `foo.bar.baz` is not recognized as a source %>
86+
<%= @other_user_raw_name.foo.bar.baz.html_safe %>

0 commit comments

Comments
 (0)