Skip to content

Commit 355f7cd

Browse files
committed
JS: Migrate PrototypePollutingMergeCall
1 parent c38e3a2 commit 355f7cd

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import semmle.javascript.security.TaintedObject
99
import semmle.javascript.dependencies.SemVer
1010

1111
module PrototypePollution {
12+
import semmle.javascript.security.CommonFlowState
13+
1214
/**
15+
* DEPRECATED. This flow label is no longer in use, and there is no corresponding flow state, as
16+
* the query instead relies on implicit reads at the sinks.
17+
*
1318
* A label for wrappers around tainted objects, that is, objects that are
1419
* not completely user-controlled, but contain a user-controlled object.
1520
*
@@ -23,12 +28,12 @@ module PrototypePollution {
2328
* }
2429
* ```
2530
*/
26-
abstract class TaintedObjectWrapper extends DataFlow::FlowLabel {
31+
abstract deprecated class TaintedObjectWrapper extends DataFlow::FlowLabel {
2732
TaintedObjectWrapper() { this = "tainted-object-wrapper" }
2833
}
2934

30-
/** Companion module to the `TaintedObjectWrapper` class. */
31-
module TaintedObjectWrapper {
35+
/** DEPRECATED. Use `FlowState::taintedObjectWrapper()` instead. */
36+
deprecated module TaintedObjectWrapper {
3237
/** Gets the instance of the `TaintedObjectWrapper` label. */
3338
TaintedObjectWrapper label() { any() }
3439
}
@@ -40,7 +45,10 @@ module PrototypePollution {
4045
/**
4146
* Gets the type of data coming from this source.
4247
*/
43-
abstract DataFlow::FlowLabel getAFlowLabel();
48+
FlowState getAFlowState() { result.isTaintedObject() }
49+
50+
/** DEPRECATED. Use `getAFlowState()` instead. */
51+
deprecated DataFlow::FlowLabel getAFlowLabel() { result = this.getAFlowState().toFlowLabel() }
4452
}
4553

4654
/**
@@ -50,7 +58,10 @@ module PrototypePollution {
5058
/**
5159
* Gets the type of data that can taint this sink.
5260
*/
53-
abstract DataFlow::FlowLabel getAFlowLabel();
61+
FlowState getAFlowState() { result.isTaintedObject() }
62+
63+
/** DEPRECATED. Use `getAFlowState()` instead. */
64+
deprecated DataFlow::FlowLabel getAFlowLabel() { result = this.getAFlowState().toFlowLabel() }
5465

5566
/**
5667
* Holds if `moduleName` is the name of the module that defines this sink,
@@ -68,14 +79,14 @@ module PrototypePollution {
6879
* in order to be flagged for prototype pollution.
6980
*/
7081
private class RemoteFlowAsSource extends Source instanceof RemoteFlowSource {
71-
override DataFlow::FlowLabel getAFlowLabel() { result.isTaint() }
82+
override FlowState getAFlowState() { result.isTaint() }
7283
}
7384

7485
/**
7586
* A source of user-controlled objects.
7687
*/
7788
private class TaintedObjectSource extends Source instanceof TaintedObject::Source {
78-
override DataFlow::FlowLabel getAFlowLabel() { result = TaintedObject::label() }
89+
override FlowState getAFlowState() { result.isTaintedObject() }
7990
}
8091

8192
class DeepExtendSink extends Sink {
@@ -98,12 +109,6 @@ module PrototypePollution {
98109
)
99110
}
100111

101-
override DataFlow::FlowLabel getAFlowLabel() {
102-
result = TaintedObject::label()
103-
or
104-
result = TaintedObjectWrapper::label()
105-
}
106-
107112
override predicate dependencyInfo(string moduleName_, Locatable loc) {
108113
moduleName = moduleName_ and
109114
location = loc

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,27 @@ deprecated private class ConcreteTaintedObjectWrapper extends TaintedObjectWrapp
2525
* leading to prototype pollution.
2626
*/
2727
module PrototypePollutionConfig implements DataFlow::StateConfigSig {
28-
class FlowState = DataFlow::FlowLabel;
28+
import semmle.javascript.security.CommonFlowState
2929

30-
predicate isSource(DataFlow::Node node, DataFlow::FlowLabel label) {
31-
node.(Source).getAFlowLabel() = label
32-
}
30+
predicate isSource(DataFlow::Node node, FlowState state) { node.(Source).getAFlowState() = state }
3331

34-
predicate isSink(DataFlow::Node node, DataFlow::FlowLabel label) {
35-
node.(Sink).getAFlowLabel() = label
36-
}
32+
predicate isSink(DataFlow::Node node, FlowState state) { node.(Sink).getAFlowState() = state }
3733

3834
predicate isAdditionalFlowStep(
39-
DataFlow::Node src, DataFlow::FlowLabel inlbl, DataFlow::Node dst, DataFlow::FlowLabel outlbl
35+
DataFlow::Node src, FlowState inlbl, DataFlow::Node dst, FlowState outlbl
4036
) {
41-
TaintedObject::step(src, dst, inlbl, outlbl)
37+
TaintedObject::isAdditionalFlowStep(src, inlbl, dst, outlbl)
4238
}
4339

4440
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet contents) {
4541
// For recursive merge sinks, the deeply tainted object only needs to be reachable from the input, the input itself
4642
// does not need to be deeply tainted.
47-
isSink(node, TaintedObject::label()) and
43+
isSink(node, FlowState::taintedObject()) and
4844
contents = DataFlow::ContentSet::anyProperty()
4945
}
5046

51-
predicate isBarrier(DataFlow::Node node, DataFlow::FlowLabel label) {
52-
node = TaintedObject::SanitizerGuard::getABarrierNode(label)
47+
predicate isBarrier(DataFlow::Node node, FlowState state) {
48+
node = TaintedObject::SanitizerGuard::getABarrierNode(state)
5349
}
5450
}
5551

0 commit comments

Comments
 (0)