Skip to content

Commit 3517729

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Convert BrowserInjectionObjectQuery.ql to use the new dataflow API
1 parent f5b53dc commit 3517729

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

javascript/src/audit/browserAPI/BrowserInjectionObjectQuery.ql

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,58 @@
99
* @tags security
1010
*/
1111

12-
1312
import javascript
14-
import DataFlow::PathGraph
13+
import ConfigFlow::PathGraph
1514
import browserextension.BrowserInjectionObjectCustomizations::BrowserInjection
1615
import DataFlow
1716
private import semmle.javascript.security.dataflow.XssThroughDomCustomizations::XssThroughDom as XssThroughDom
1817

1918

20-
class ObjectLabel extends DataFlow::FlowLabel {
21-
ObjectLabel() {
22-
this = "Object"
23-
}
19+
class ObjectState extends string {
20+
ObjectState() { this = "Object" }
2421
}
2522

2623
/**
2724
* Gets either a standard flow label or the partial-taint label.
2825
*/
29-
DataFlow::FlowLabel anyLabel() {
30-
result.isDataOrTaint()
31-
}
26+
string anyLabel() { result = ["data", "taint"] }
3227

3328

34-
class Configuration extends TaintTracking::Configuration {
35-
Configuration() { this = "BrowserInjection" }
36-
37-
override predicate isSource(DataFlow::Node source) {
38-
source instanceof Source // optional: or source instanceof XssThroughDom::Source
29+
module Config implements DataFlow::StateConfigSig {
30+
class FlowState extends string {
31+
FlowState() { this = anyLabel() or this instanceof ObjectState }
32+
}
33+
34+
predicate isSource(DataFlow::Node source, FlowState state) {
35+
source instanceof Source and // optional: or source instanceof XssThroughDom::Source
36+
(
37+
state = anyLabel()
38+
or
39+
state instanceof ObjectState
40+
)
3941
}
4042

41-
override predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel lbl) {
42-
sink instanceof Sink and lbl instanceof ObjectLabel
43+
predicate isSink(DataFlow::Node sink, FlowState state) {
44+
sink instanceof Sink and state instanceof ObjectState
4345
}
4446

45-
override predicate isAdditionalFlowStep(
46-
DataFlow::Node src, DataFlow::Node trg, DataFlow::FlowLabel inlbl, DataFlow::FlowLabel outlbl
47+
predicate isAdditionalFlowStep(
48+
DataFlow::Node src, FlowState inState, DataFlow::Node trg, FlowState outState
4749
) {
4850
// writing a tainted value to an object property makes the object tainted with ObjectLabel
4951
exists(DataFlow::PropWrite write |
5052
write.getRhs() = src and
51-
inlbl = anyLabel() and
53+
inState = anyLabel() and
5254
trg.(DataFlow::SourceNode).flowsTo(write.getBase()) and
53-
outlbl instanceof ObjectLabel
55+
outState instanceof ObjectState
5456
)
5557
}
5658
}
5759

60+
module ConfigFlow = TaintTracking::GlobalWithState<Config>;
5861

59-
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
60-
where cfg.hasFlowPath(source, sink)
62+
from ConfigFlow::PathNode source, ConfigFlow::PathNode sink
63+
where ConfigFlow::flowPath(source, sink)
6164
select sink.getNode(), source, sink, sink.getNode() + " depends on a $@.",
6265
source.getNode(), "user-provided value"
6366

0 commit comments

Comments
 (0)