Skip to content

Commit c38e3a2

Browse files
committed
JS: Migrate NoSqlInjection
1 parent 8e8de5c commit c38e3a2

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

javascript/ql/lib/semmle/javascript/security/dataflow/NosqlInjectionCustomizations.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import javascript
88
import semmle.javascript.security.TaintedObject
99

1010
module NosqlInjection {
11+
import semmle.javascript.security.CommonFlowState
12+
1113
/**
1214
* A data flow source for NoSQL injection vulnerabilities.
1315
*/
@@ -22,7 +24,10 @@ module NosqlInjection {
2224
*
2325
* Defaults to deeply tainted objects only.
2426
*/
25-
DataFlow::FlowLabel getAFlowLabel() { result = TaintedObject::label() }
27+
FlowState getAFlowState() { result.isTaintedObject() }
28+
29+
/** DEPRECATED. Use `getAFlowState()` instead. */
30+
deprecated DataFlow::FlowLabel getAFlowLabel() { result = this.getAFlowState().toFlowLabel() }
2631
}
2732

2833
/**

javascript/ql/lib/semmle/javascript/security/dataflow/NosqlInjectionQuery.qll

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,17 @@ import NosqlInjectionCustomizations::NosqlInjection
1515
* A taint-tracking configuration for reasoning about SQL-injection vulnerabilities.
1616
*/
1717
module NosqlInjectionConfig implements DataFlow::StateConfigSig {
18-
class FlowState = DataFlow::FlowLabel;
18+
import semmle.javascript.security.CommonFlowState
1919

20-
predicate isSource(DataFlow::Node source, DataFlow::FlowLabel state) {
20+
predicate isSource(DataFlow::Node source, FlowState state) {
2121
source instanceof Source and state.isTaint()
2222
or
23-
TaintedObject::isSource(source, state)
23+
source instanceof TaintedObject::Source and state.isTaintedObject()
2424
}
2525

26-
predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel state) {
27-
sink.(Sink).getAFlowLabel() = state
28-
}
26+
predicate isSink(DataFlow::Node sink, FlowState state) { sink.(Sink).getAFlowState() = state }
2927

30-
predicate isBarrier(DataFlow::Node node, DataFlow::FlowLabel state) {
28+
predicate isBarrier(DataFlow::Node node, FlowState state) {
3129
node instanceof Sanitizer and state.isTaint()
3230
or
3331
TaintTracking::defaultSanitizer(node) and state.isTaint()
@@ -36,14 +34,13 @@ module NosqlInjectionConfig implements DataFlow::StateConfigSig {
3634
}
3735

3836
predicate isAdditionalFlowStep(
39-
DataFlow::Node node1, DataFlow::FlowLabel state1, DataFlow::Node node2,
40-
DataFlow::FlowLabel state2
37+
DataFlow::Node node1, FlowState state1, DataFlow::Node node2, FlowState state2
4138
) {
42-
TaintedObject::step(node1, node2, state1, state2)
39+
TaintedObject::isAdditionalFlowStep(node1, state1, node2, state2)
4340
or
4441
// additional flow step to track taint through NoSQL query objects
45-
state1 = TaintedObject::label() and
46-
state2 = TaintedObject::label() and
42+
state1.isTaintedObject() and
43+
state2.isTaintedObject() and
4744
exists(NoSql::Query query, DataFlow::SourceNode queryObj |
4845
queryObj.flowsTo(query) and
4946
queryObj.flowsTo(node2) and
@@ -90,6 +87,7 @@ deprecated class Configuration extends TaintTracking::Configuration {
9087
DataFlow::Node node1, DataFlow::Node node2, DataFlow::FlowLabel state1,
9188
DataFlow::FlowLabel state2
9289
) {
93-
NosqlInjectionConfig::isAdditionalFlowStep(node1, state1, node2, state2)
90+
NosqlInjectionConfig::isAdditionalFlowStep(node1, FlowState::fromFlowLabel(state1), node2,
91+
FlowState::fromFlowLabel(state2))
9492
}
9593
}

0 commit comments

Comments
 (0)