Skip to content

Commit b6ca4fb

Browse files
committed
JS: Add getDefaultSourceLabel()
1 parent 7393844 commit b6ca4fb

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

javascript/ql/src/semmle/javascript/dataflow/Configuration.qll

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ abstract class Configuration extends string {
9898
*/
9999
predicate isSource(DataFlow::Node source) { none() }
100100

101+
/**
102+
* Gets the flow label to associate with sources added by the 1-argument `isSource` predicate.
103+
*
104+
* For taint-tracking configurations, this defaults to `taint` and for other data-flow configurations
105+
* it defaults to `data`.
106+
*
107+
* Overriding this predicate is rarely needed, and overriding the 2-argument `isSource` predicate
108+
* should be preferred when possible.
109+
*/
110+
FlowLabel getDefaultSourceLabel() { result = FlowLabel::data() }
111+
101112
/**
102113
* Holds if `source` is a source of flow labeled with `lbl` that is relevant
103114
* for this configuration.
@@ -668,11 +679,7 @@ private predicate exploratoryFlowStep(
668679
*/
669680
private predicate isSource(DataFlow::Node nd, DataFlow::Configuration cfg, FlowLabel lbl) {
670681
(cfg.isSource(nd) or nd.(AdditionalSource).isSourceFor(cfg)) and
671-
(
672-
if cfg instanceof TaintTracking::Configuration
673-
then lbl = FlowLabel::taint()
674-
else lbl = FlowLabel::data()
675-
)
682+
lbl = cfg.getDefaultSourceLabel()
676683
or
677684
nd.(AdditionalSource).isSourceFor(cfg, lbl)
678685
or
@@ -684,11 +691,7 @@ private predicate isSource(DataFlow::Node nd, DataFlow::Configuration cfg, FlowL
684691
*/
685692
private predicate isSink(DataFlow::Node nd, DataFlow::Configuration cfg, FlowLabel lbl) {
686693
(cfg.isSink(nd) or nd.(AdditionalSink).isSinkFor(cfg)) and
687-
(
688-
if cfg instanceof TaintTracking::Configuration
689-
then lbl = FlowLabel::taint()
690-
else lbl = FlowLabel::data()
691-
)
694+
lbl = any(StandardFlowLabel f)
692695
or
693696
nd.(AdditionalSink).isSinkFor(cfg, lbl)
694697
or

javascript/ql/src/semmle/javascript/dataflow/TaintTracking.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ module TaintTracking {
146146
) {
147147
isAdditionalFlowStep(pred, succ) and valuePreserving = false
148148
}
149+
150+
override DataFlow::FlowLabel getDefaultSourceLabel() { result.isTaint() }
149151
}
150152

151153
/**
@@ -201,10 +203,6 @@ module TaintTracking {
201203
* A sanitizer guard node that only blocks specific flow labels.
202204
*/
203205
abstract class LabeledSanitizerGuardNode extends SanitizerGuardNode, DataFlow::BarrierGuardNode {
204-
final override predicate blocks(boolean outcome, Expr e, DataFlow::FlowLabel label) {
205-
sanitizes(outcome, e, label)
206-
}
207-
208206
override predicate sanitizes(boolean outcome, Expr e) { none() }
209207
}
210208

0 commit comments

Comments
 (0)