Skip to content

Commit 8907252

Browse files
committed
JS: Migrate TemplateObjectInjection
1 parent 3573f0b commit 8907252

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ private import semmle.javascript.security.TaintedObjectCustomizations
1212
* template object injection vulnerabilities.
1313
*/
1414
module TemplateObjectInjection {
15+
import semmle.javascript.security.CommonFlowState
16+
1517
/**
1618
* A data flow source for template object injection vulnerabilities.
1719
*/
1820
abstract class Source extends DataFlow::Node {
19-
/** Gets a flow label to associate with this source. */
20-
abstract DataFlow::FlowLabel getAFlowLabel();
21+
/** Gets a flow state for which this is a source. */
22+
FlowState getAFlowState() { result.isTaint() }
23+
24+
/** DEPRECATED. Use `getAFlowState()` instead */
25+
deprecated DataFlow::FlowLabel getAFlowLabel() { result = this.getAFlowState().toFlowLabel() }
2126
}
2227

2328
/**
@@ -31,12 +36,12 @@ module TemplateObjectInjection {
3136
abstract class Sanitizer extends DataFlow::Node { }
3237

3338
private class TaintedObjectSourceAsSource extends Source instanceof TaintedObject::Source {
34-
override DataFlow::FlowLabel getAFlowLabel() { result = TaintedObject::label() }
39+
override FlowState getAFlowState() { result.isTaintedObject() }
3540
}
3641

3742
/** An active threat-model source, considered as a flow source. */
3843
private class ActiveThreatModelSourceAsSource extends Source, ActiveThreatModelSource {
39-
override DataFlow::FlowLabel getAFlowLabel() { result.isTaint() }
44+
override FlowState getAFlowState() { result.isTaint() }
4045
}
4146

4247
/**

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@ private import semmle.javascript.security.TaintedObject
1515
* A taint tracking configuration for reasoning about template object injection vulnerabilities.
1616
*/
1717
module TemplateObjectInjectionConfig implements DataFlow::StateConfigSig {
18-
class FlowState = DataFlow::FlowLabel;
18+
import semmle.javascript.security.CommonFlowState
1919

20-
predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
21-
source.(Source).getAFlowLabel() = label
20+
predicate isSource(DataFlow::Node source, FlowState state) {
21+
source.(Source).getAFlowState() = state
2222
}
2323

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

2828
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
2929

30-
predicate isBarrier(DataFlow::Node node, DataFlow::FlowLabel label) {
30+
predicate isBarrier(DataFlow::Node node, FlowState state) {
3131
TaintTracking::defaultSanitizer(node) and
32-
label.isTaint()
32+
state.isTaint()
3333
or
34-
node = TaintedObject::SanitizerGuard::getABarrierNode(label)
34+
node = TaintedObject::SanitizerGuard::getABarrierNode(state)
3535
}
3636

3737
predicate isAdditionalFlowStep(
38-
DataFlow::Node src, DataFlow::FlowLabel inlbl, DataFlow::Node trg, DataFlow::FlowLabel outlbl
38+
DataFlow::Node src, FlowState inlbl, DataFlow::Node trg, FlowState outlbl
3939
) {
40-
TaintedObject::step(src, trg, inlbl, outlbl)
40+
TaintedObject::isAdditionalFlowStep(src, inlbl, trg, outlbl)
4141
or
4242
// We're not using a taint-tracking config because taint steps would then apply to all flow states.
4343
// So we use a plain data flow config and manually add the default taint steps.

0 commit comments

Comments
 (0)