Skip to content

Commit 8e8de5c

Browse files
committed
JS: Migrate LoopBoundInjection
1 parent daddff0 commit 8e8de5c

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import javascript
88

99
module LoopBoundInjection {
1010
import semmle.javascript.security.TaintedObject
11+
import semmle.javascript.security.CommonFlowState
1112

1213
/**
1314
* Holds if an exception will be thrown whenever `e` evaluates to `undefined` or `null`.
@@ -176,16 +177,16 @@ module LoopBoundInjection {
176177
predicate blocksExpr(boolean outcome, Expr e) { none() }
177178

178179
/**
179-
* Holds if this node acts as a barrier for `label`, blocking further flow from `e` if `this` evaluates to `outcome`.
180+
* Holds if this node acts as a barrier for `state`, blocking further flow from `e` if `this` evaluates to `outcome`.
180181
*/
181-
predicate blocksExpr(boolean outcome, Expr e, DataFlow::FlowLabel label) { none() }
182+
predicate blocksExpr(boolean outcome, Expr e, FlowState state) { none() }
182183

183184
/** DEPRECATED. Use `blocksExpr` instead. */
184185
deprecated predicate sanitizes(boolean outcome, Expr e) { this.blocksExpr(outcome, e) }
185186

186187
/** DEPRECATED. Use `blocksExpr` instead. */
187188
deprecated predicate sanitizes(boolean outcome, Expr e, DataFlow::FlowLabel label) {
188-
this.blocksExpr(outcome, e, label)
189+
this.blocksExpr(outcome, e, FlowState::fromFlowLabel(label))
189190
}
190191
}
191192

@@ -214,10 +215,10 @@ module LoopBoundInjection {
214215

215216
IsArraySanitizerGuard() { astNode.getCalleeName() = "isArray" }
216217

217-
override predicate blocksExpr(boolean outcome, Expr e, DataFlow::FlowLabel label) {
218+
override predicate blocksExpr(boolean outcome, Expr e, FlowState state) {
218219
true = outcome and
219220
e = astNode.getAnArgument() and
220-
label = TaintedObject::label()
221+
state.isTaintedObject()
221222
}
222223
}
223224

@@ -232,10 +233,10 @@ module LoopBoundInjection {
232233
DataFlow::globalVarRef("Array").flowsToExpr(astNode.getRightOperand())
233234
}
234235

235-
override predicate blocksExpr(boolean outcome, Expr e, DataFlow::FlowLabel label) {
236+
override predicate blocksExpr(boolean outcome, Expr e, FlowState state) {
236237
true = outcome and
237238
e = astNode.getLeftOperand() and
238-
label = TaintedObject::label()
239+
state.isTaintedObject()
239240
}
240241
}
241242

@@ -253,10 +254,10 @@ module LoopBoundInjection {
253254
propRead.getPropertyName() = "length"
254255
}
255256

256-
override predicate blocksExpr(boolean outcome, Expr e, DataFlow::FlowLabel label) {
257+
override predicate blocksExpr(boolean outcome, Expr e, FlowState state) {
257258
false = outcome and
258259
e = propRead.getBase().asExpr() and
259-
label = TaintedObject::label()
260+
state.isTaintedObject()
260261
}
261262
}
262263
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,29 @@ import LoopBoundInjectionCustomizations::LoopBoundInjection
1414
* A taint tracking configuration for reasoning about looping on tainted objects with unbounded length.
1515
*/
1616
module LoopBoundInjectionConfig implements DataFlow::StateConfigSig {
17-
class FlowState = DataFlow::FlowLabel;
17+
import semmle.javascript.security.CommonFlowState
1818

19-
predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
20-
source instanceof Source and label = TaintedObject::label()
19+
predicate isSource(DataFlow::Node source, FlowState state) {
20+
source instanceof Source and state.isTaintedObject()
2121
}
2222

23-
predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel label) {
24-
sink instanceof Sink and label = TaintedObject::label()
23+
predicate isSink(DataFlow::Node sink, FlowState state) {
24+
sink instanceof Sink and state.isTaintedObject()
2525
}
2626

2727
predicate isBarrier(DataFlow::Node node) {
2828
node = DataFlow::MakeBarrierGuard<BarrierGuard>::getABarrierNode()
2929
}
3030

31-
predicate isBarrier(DataFlow::Node node, DataFlow::FlowLabel label) {
32-
node = DataFlow::MakeLabeledBarrierGuard<BarrierGuard>::getABarrierNode(label) or
33-
node = TaintedObject::SanitizerGuard::getABarrierNode(label)
31+
predicate isBarrier(DataFlow::Node node, FlowState state) {
32+
node = DataFlow::MakeStateBarrierGuard<FlowState, BarrierGuard>::getABarrierNode(state) or
33+
node = TaintedObject::SanitizerGuard::getABarrierNode(state)
3434
}
3535

3636
predicate isAdditionalFlowStep(
37-
DataFlow::Node src, DataFlow::FlowLabel inlbl, DataFlow::Node trg, DataFlow::FlowLabel outlbl
37+
DataFlow::Node src, FlowState inlbl, DataFlow::Node trg, FlowState outlbl
3838
) {
39-
TaintedObject::step(src, trg, inlbl, outlbl)
39+
TaintedObject::isAdditionalFlowStep(src, inlbl, trg, outlbl)
4040
}
4141
}
4242

0 commit comments

Comments
 (0)