Skip to content

Commit bd15994

Browse files
authored
Merge pull request #1367 from xiemaisi/js/configuration-api-consistency
Approved by esben-semmle
2 parents 9804105 + 86e96c6 commit bd15994

File tree

9 files changed

+53
-15
lines changed

9 files changed

+53
-15
lines changed

change-notes/1.21/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
* `RegExpLiteral` is now a `DataFlow::SourceNode`.
5252
* `JSDocTypeExpr` now has source locations and is a subclass of `Locatable` and `TypeAnnotation`.
53+
* The two-parameter versions of predicate `isBarrier` in `DataFlow::Configuration` and of predicate `isSanitizer` in `TaintTracking::Configuration` have been renamed to `isBarrierEdge` and `isSanitizerEdge`, respectively. The old names are maintained for backwards-compatibility in this version, but will be deprecated in the next version and subsequently removed.
5354
* Various predicates named `getTypeAnnotation()` now return `TypeAnnotation` instead of `TypeExpr`.
5455
In rare cases, this may cause compilation errors in existing code. Cast the result to `TypeExpr` if this happens.
5556
* The `getALabel` predicate in `LabeledBarrierGuardNode` and `LabeledSanitizerGuardNode`

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,29 @@ abstract class Configuration extends string {
153153
}
154154

155155
/**
156+
* DEPRECATED: Use `isBarrierEdge` instead.
157+
*
156158
* Holds if flow from `src` to `trg` is prohibited.
157159
*/
158160
predicate isBarrier(DataFlow::Node src, DataFlow::Node trg) { none() }
159161

160162
/**
163+
* DEPRECATED: Use `isBarrierEdge` instead.
164+
*
161165
* Holds if flow with label `lbl` cannot flow from `src` to `trg`.
162166
*/
163167
predicate isBarrier(DataFlow::Node src, DataFlow::Node trg, FlowLabel lbl) { none() }
164168

169+
/**
170+
* Holds if flow from `pred` to `succ` is prohibited.
171+
*/
172+
predicate isBarrierEdge(DataFlow::Node pred, DataFlow::Node succ) { none() }
173+
174+
/**
175+
* Holds if flow with label `lbl` cannot flow from `pred` to `succ`.
176+
*/
177+
predicate isBarrierEdge(DataFlow::Node pred, DataFlow::Node succ, FlowLabel lbl) { none() }
178+
165179
/**
166180
* Holds if flow with label `lbl` cannot flow into `node`.
167181
*/
@@ -473,6 +487,7 @@ private predicate basicFlowStep(
473487
exists(FlowLabel predlbl, FlowLabel succlbl |
474488
localFlowStep(pred, succ, cfg, predlbl, succlbl) and
475489
not cfg.isBarrier(pred, succ, predlbl) and
490+
not cfg.isBarrierEdge(pred, succ, predlbl) and
476491
summary = MkPathSummary(false, false, predlbl, succlbl)
477492
)
478493
or
@@ -586,7 +601,8 @@ private predicate callInputStep(
586601
)
587602
) and
588603
not cfg.isBarrier(succ) and
589-
not cfg.isBarrier(pred, succ)
604+
not cfg.isBarrier(pred, succ) and
605+
not cfg.isBarrierEdge(pred, succ)
590606
}
591607

592608
/**
@@ -641,6 +657,7 @@ private predicate flowThroughCall(
641657
calls(output, f) and // Do not consider partial calls
642658
reachableFromInput(f, output, input, ret, cfg, summary) and
643659
not cfg.isBarrier(ret, output) and
660+
not cfg.isBarrierEdge(ret, output) and
644661
not cfg.isLabeledBarrier(output, summary.getEndLabel())
645662
)
646663
or
@@ -650,6 +667,7 @@ private predicate flowThroughCall(
650667
calls(invk, f) and
651668
reachableFromInput(f, invk, input, ret, cfg, summary) and
652669
not cfg.isBarrier(ret, output) and
670+
not cfg.isBarrierEdge(ret, output) and
653671
not cfg.isLabeledBarrier(output, summary.getEndLabel())
654672
)
655673
}
@@ -836,6 +854,7 @@ private predicate flowStep(
836854
) and
837855
not cfg.isBarrier(succ) and
838856
not cfg.isBarrier(pred, succ) and
857+
not cfg.isBarrierEdge(pred, succ) and
839858
not cfg.isLabeledBarrier(succ, summary.getEndLabel())
840859
}
841860

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,30 @@ module TaintTracking {
5151
/** Holds if the intermediate node `node` is a taint sanitizer. */
5252
predicate isSanitizer(DataFlow::Node node) { none() }
5353

54-
/** Holds if the edge from `source` to `sink` is a taint sanitizer. */
54+
/**
55+
* DEPRECATED: Use `isSanitizerEdge` instead.
56+
*
57+
* Holds if the edge from `source` to `sink` is a taint sanitizer.
58+
*/
5559
predicate isSanitizer(DataFlow::Node source, DataFlow::Node sink) { none() }
5660

57-
/** Holds if the edge from `source` to `sink` is a taint sanitizer for data labelled with `lbl`. */
61+
/**
62+
* DEPRECATED: Use `isSanitizerEdge` instead.
63+
*
64+
* Holds if the edge from `source` to `sink` is a taint sanitizer for data labelled with `lbl`.
65+
*/
5866
predicate isSanitizer(DataFlow::Node source, DataFlow::Node sink, DataFlow::FlowLabel lbl) {
5967
none()
6068
}
6169

70+
/** Holds if the edge from `pred` to `succ` is a taint sanitizer. */
71+
predicate isSanitizerEdge(DataFlow::Node pred, DataFlow::Node succ) { none() }
72+
73+
/** Holds if the edge from `pred` to `succ` is a taint sanitizer for data labelled with `lbl`. */
74+
predicate isSanitizerEdge(DataFlow::Node pred, DataFlow::Node succ, DataFlow::FlowLabel lbl) {
75+
none()
76+
}
77+
6278
/**
6379
* Holds if data flow node `guard` can act as a sanitizer when appearing
6480
* in a condition.
@@ -74,16 +90,18 @@ module TaintTracking {
7490
isSanitizer(node)
7591
}
7692

77-
final override predicate isBarrier(DataFlow::Node source, DataFlow::Node sink) {
78-
super.isBarrier(source, sink) or
79-
isSanitizer(source, sink)
93+
final override predicate isBarrierEdge(DataFlow::Node source, DataFlow::Node sink) {
94+
super.isBarrierEdge(source, sink) or
95+
isSanitizer(source, sink) or
96+
isSanitizerEdge(source, sink)
8097
}
8198

82-
final override predicate isBarrier(
99+
final override predicate isBarrierEdge(
83100
DataFlow::Node source, DataFlow::Node sink, DataFlow::FlowLabel lbl
84101
) {
85-
super.isBarrier(source, sink, lbl) or
86-
isSanitizer(source, sink, lbl)
102+
super.isBarrierEdge(source, sink, lbl) or
103+
isSanitizer(source, sink, lbl) or
104+
isSanitizerEdge(source, sink, lbl)
87105
}
88106

89107
final override predicate isBarrierGuard(DataFlow::BarrierGuardNode guard) {

javascript/ql/src/semmle/javascript/security/dataflow/ClientSideUrlRedirect.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module ClientSideUrlRedirect {
5151
node instanceof Sanitizer
5252
}
5353

54-
override predicate isSanitizer(DataFlow::Node source, DataFlow::Node sink) {
54+
override predicate isSanitizerEdge(DataFlow::Node source, DataFlow::Node sink) {
5555
hostnameSanitizingPrefixEdge(source, sink)
5656
}
5757

javascript/ql/src/semmle/javascript/security/dataflow/InsecureRandomness.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module InsecureRandomness {
3636
node instanceof Sanitizer
3737
}
3838

39-
override predicate isSanitizer(DataFlow::Node pred, DataFlow::Node succ) {
39+
override predicate isSanitizerEdge(DataFlow::Node pred, DataFlow::Node succ) {
4040
// stop propagation at the sinks to avoid double reporting
4141
pred instanceof Sink and
4242
// constrain succ

javascript/ql/src/semmle/javascript/security/dataflow/RequestForgery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module RequestForgery {
4646
node instanceof Sanitizer
4747
}
4848

49-
override predicate isSanitizer(DataFlow::Node source, DataFlow::Node sink) {
49+
override predicate isSanitizerEdge(DataFlow::Node source, DataFlow::Node sink) {
5050
sanitizingPrefixEdge(source, sink)
5151
}
5252
}

javascript/ql/src/semmle/javascript/security/dataflow/ServerSideUrlRedirect.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module ServerSideUrlRedirect {
3838
node instanceof Sanitizer
3939
}
4040

41-
override predicate isSanitizer(DataFlow::Node source, DataFlow::Node sink) {
41+
override predicate isSanitizerEdge(DataFlow::Node source, DataFlow::Node sink) {
4242
hostnameSanitizingPrefixEdge(source, sink)
4343
}
4444

javascript/ql/test/library-tests/InterProceduralFlow/DataFlowConfig.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TestDataFlowConfiguration extends DataFlow::Configuration {
1717
)
1818
}
1919

20-
override predicate isBarrier(DataFlow::Node src, DataFlow::Node snk) {
20+
override predicate isBarrierEdge(DataFlow::Node src, DataFlow::Node snk) {
2121
src = src and
2222
snk.asExpr().(PropAccess).getPropertyName() = "notTracked"
2323
or

javascript/ql/test/library-tests/InterProceduralFlow/TaintTracking.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TestTaintTrackingConfiguration extends TaintTracking::Configuration {
1717
)
1818
}
1919

20-
override predicate isSanitizer(DataFlow::Node src, DataFlow::Node snk) {
20+
override predicate isSanitizerEdge(DataFlow::Node src, DataFlow::Node snk) {
2121
src = src and
2222
snk.asExpr().(PropAccess).getPropertyName() = "notTracked"
2323
or

0 commit comments

Comments
 (0)