Skip to content

Commit b6a709d

Browse files
committed
Ruby: Rewrite Stored XSS query to use new data flow interface
1 parent ff53e53 commit b6a709d

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ module StoredXss {
1616
import XSS::StoredXss
1717

1818
/**
19+
* DEPRECATED.
20+
*
1921
* A taint-tracking configuration for reasoning about Stored XSS.
2022
*/
21-
class Configuration extends TaintTracking::Configuration {
23+
deprecated class Configuration extends TaintTracking::Configuration {
2224
Configuration() { this = "StoredXss" }
2325

2426
override predicate isSource(DataFlow::Node source) { source instanceof Source }
@@ -38,6 +40,23 @@ module StoredXss {
3840
isAdditionalXssTaintStep(node1, node2)
3941
}
4042
}
43+
44+
/**
45+
* A taint-tracking configuration for reasoning about Stored XSS.
46+
*/
47+
private module Config implements DataFlow::ConfigSig {
48+
predicate isSource(DataFlow::Node source) { source instanceof Source }
49+
50+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
51+
52+
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
53+
54+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
55+
isAdditionalXssTaintStep(node1, node2)
56+
}
57+
}
58+
59+
import TaintTracking::Make<Config>
4160
}
4261

4362
/** DEPRECATED: Alias for StoredXss */

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
private import codeql.ruby.AST
66
private import codeql.ruby.DataFlow
7-
private import codeql.ruby.DataFlow2
87
private import codeql.ruby.CFG
98
private import codeql.ruby.Concepts
109
private import codeql.ruby.Frameworks
@@ -291,20 +290,18 @@ private module OrmTracking {
291290
/**
292291
* A data flow configuration to track flow from finder calls to field accesses.
293292
*/
294-
class Configuration extends DataFlow2::Configuration {
295-
Configuration() { this = "OrmTracking" }
296-
297-
override predicate isSource(DataFlow2::Node source) { source instanceof OrmInstantiation }
293+
private module Config implements DataFlow::ConfigSig {
294+
predicate isSource(DataFlow::Node source) { source instanceof OrmInstantiation }
298295

299296
// Select any call receiver and narrow down later
300-
override predicate isSink(DataFlow2::Node sink) {
301-
sink = any(DataFlow2::CallNode c).getReceiver()
302-
}
297+
predicate isSink(DataFlow::Node sink) { sink = any(DataFlow::CallNode c).getReceiver() }
303298

304-
override predicate isAdditionalFlowStep(DataFlow2::Node node1, DataFlow2::Node node2) {
299+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
305300
Shared::isAdditionalXssFlowStep(node1, node2)
306301
}
307302
}
303+
304+
import DataFlow::Make<Config>
308305
}
309306

310307
/** Provides default sources, sinks and sanitizers for detecting stored cross-site scripting (XSS) vulnerabilities. */
@@ -333,10 +330,10 @@ module StoredXss {
333330
/** DEPRECATED: Alias for isAdditionalXssTaintStep */
334331
deprecated predicate isAdditionalXSSTaintStep = isAdditionalXssTaintStep/2;
335332

336-
private class OrmFieldAsSource extends Source instanceof DataFlow2::CallNode {
333+
private class OrmFieldAsSource extends Source instanceof DataFlow::CallNode {
337334
OrmFieldAsSource() {
338-
exists(OrmTracking::Configuration subConfig, DataFlow2::CallNode subSrc |
339-
subConfig.hasFlow(subSrc, this.getReceiver()) and
335+
exists(DataFlow::CallNode subSrc |
336+
OrmTracking::hasFlow(subSrc, this.getReceiver()) and
340337
subSrc.(OrmInstantiation).methodCallMayAccessField(this.getMethodName())
341338
)
342339
}

ruby/ql/src/queries/security/cwe-079/StoredXSS.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
import codeql.ruby.AST
1616
import codeql.ruby.security.StoredXSSQuery
17-
import DataFlow::PathGraph
17+
import StoredXss::PathGraph
1818

19-
from StoredXss::Configuration config, DataFlow::PathNode source, DataFlow::PathNode sink
20-
where config.hasFlowPath(source, sink)
19+
from StoredXss::PathNode source, StoredXss::PathNode sink
20+
where StoredXss::hasFlowPath(source, sink)
2121
select sink.getNode(), source, sink, "Stored cross-site scripting vulnerability due to $@.",
2222
source.getNode(), "stored value"

0 commit comments

Comments
 (0)