Skip to content

Commit f03f670

Browse files
committed
Ruby: configsig rb/html-constructed-from-input
1 parent 8ad6c72 commit f03f670

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* Provides a taint-tracking configuration for reasoning about HTML
33
* constructed from library input vulnerabilities.
44
*
5-
* Note, for performance reasons: only import this file if `Configuration` is needed,
6-
* otherwise `UnsafeHtmlConstructionCustomizations` should be imported instead.
5+
* Note, for performance reasons: only import this file if
6+
* `UnsafeHtmlConstructionFlow` is needed, otherwise
7+
* `UnsafeHtmlConstructionCustomizations` should be imported instead.
78
*/
89

910
import codeql.ruby.DataFlow
@@ -13,8 +14,9 @@ private import codeql.ruby.dataflow.BarrierGuards
1314

1415
/**
1516
* A taint-tracking configuration for detecting unsafe HTML construction.
17+
* DEPRECATED: Use `UnsafeHtmlConstructionFlow`
1618
*/
17-
class Configuration extends TaintTracking::Configuration {
19+
deprecated class Configuration extends TaintTracking::Configuration {
1820
Configuration() { this = "UnsafeHtmlConstruction" }
1921

2022
override predicate isSource(DataFlow::Node source) { source instanceof Source }
@@ -31,3 +33,22 @@ class Configuration extends TaintTracking::Configuration {
3133
result instanceof DataFlow::FeatureHasSourceCallContext
3234
}
3335
}
36+
37+
private module UnsafeHtmlConstructionConfig implements DataFlow::ConfigSig {
38+
predicate isSource(DataFlow::Node source) { source instanceof Source }
39+
40+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
41+
42+
predicate isBarrier(DataFlow::Node node) {
43+
node instanceof StringConstCompareBarrier or
44+
node instanceof StringConstArrayInclusionCallBarrier
45+
}
46+
47+
// override to require the path doesn't have unmatched return steps
48+
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }
49+
}
50+
51+
/**
52+
* Taint-tracking for detecting unsafe HTML construction.
53+
*/
54+
module UnsafeHtmlConstructionFlow = TaintTracking::Global<UnsafeHtmlConstructionConfig>;

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
*/
1414

1515
import codeql.ruby.security.UnsafeHtmlConstructionQuery
16-
import DataFlow::PathGraph
16+
import UnsafeHtmlConstructionFlow::PathGraph
1717

18-
from DataFlow::Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink, Sink sinkNode
19-
where cfg.hasFlowPath(source, sink) and sink.getNode() = sinkNode
18+
from
19+
UnsafeHtmlConstructionFlow::PathNode source, UnsafeHtmlConstructionFlow::PathNode sink,
20+
Sink sinkNode
21+
where UnsafeHtmlConstructionFlow::flowPath(source, sink) and sink.getNode() = sinkNode
2022
select sinkNode, source, sink,
2123
"This " + sinkNode.getSinkType() + " which depends on $@ might later allow $@.", source.getNode(),
2224
"library input", sinkNode.getXssSink(), "cross-site scripting"

0 commit comments

Comments
 (0)