Skip to content

Commit bcec7ee

Browse files
authored
Merge pull request #18633 from aschackmull/dataflow/refactor-flowstate
Dataflow: Refactor FlowState to be paired with Node
2 parents 670ecb3 + 73d7250 commit bcec7ee

File tree

6 files changed

+5241
-4901
lines changed

6 files changed

+5241
-4901
lines changed

javascript/ql/src/Security/CWE-915/PrototypePollutingFunction.ql

+13-19
Original file line numberDiff line numberDiff line change
@@ -251,25 +251,19 @@ module PropNameTrackingConfig implements DataFlow::StateConfigSig {
251251
node = DataFlow::MakeStateBarrierGuard<FlowState, BarrierGuard>::getABarrierNode(state)
252252
}
253253

254-
predicate isAdditionalFlowStep(
255-
DataFlow::Node node1, FlowState state1, DataFlow::Node node2, FlowState state2
256-
) {
257-
exists(state1) and
258-
state2 = state1 and
259-
(
260-
// Step through `p -> x[p]`
261-
exists(DataFlow::PropRead read |
262-
node1 = read.getPropertyNameExpr().flow() and
263-
not read.(DynamicPropRead).hasDominatingAssignment() and
264-
node2 = read
265-
)
266-
or
267-
// Step through `x -> x[p]`
268-
exists(DynamicPropRead read |
269-
not read.hasDominatingAssignment() and
270-
node1 = read.getBase() and
271-
node2 = read
272-
)
254+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
255+
// Step through `p -> x[p]`
256+
exists(DataFlow::PropRead read |
257+
node1 = read.getPropertyNameExpr().flow() and
258+
not read.(DynamicPropRead).hasDominatingAssignment() and
259+
node2 = read
260+
)
261+
or
262+
// Step through `x -> x[p]`
263+
exists(DynamicPropRead read |
264+
not read.hasDominatingAssignment() and
265+
node1 = read.getBase() and
266+
node2 = read
273267
)
274268
}
275269

shared/dataflow/codeql/dataflow/DataFlow.qll

+15-2
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ private module PathGraphSigMod {
643643
module DataFlowMake<LocationSig Location, InputSig<Location> Lang> {
644644
private import Lang
645645
private import internal.DataFlowImpl::MakeImpl<Location, Lang>
646+
private import internal.DataFlowImplStage1::MakeImplStage1<Location, Lang>
646647
import Configs<Location, Lang>
647648

648649
/**
@@ -700,7 +701,13 @@ module DataFlowMake<LocationSig Location, InputSig<Location> Lang> {
700701
}
701702
}
702703

703-
import Impl<C>
704+
private module Stage1 = ImplStage1<C>;
705+
706+
import Stage1::PartialFlow
707+
708+
private module Flow = Impl<C, Stage1::Stage1NoState>;
709+
710+
import Flow
704711
}
705712

706713
/**
@@ -723,7 +730,13 @@ module DataFlowMake<LocationSig Location, InputSig<Location> Lang> {
723730
}
724731
}
725732

726-
import Impl<C>
733+
private module Stage1 = ImplStage1<C>;
734+
735+
import Stage1::PartialFlow
736+
737+
private module Flow = Impl<C, Stage1::Stage1WithState>;
738+
739+
import Flow
727740
}
728741

729742
signature class PathNodeSig {

shared/dataflow/codeql/dataflow/TaintTracking.qll

+30-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
private import DataFlow as DF
77
private import internal.DataFlowImpl
8+
private import internal.DataFlowImplStage1
89
private import codeql.util.Location
910

1011
/**
@@ -47,6 +48,7 @@ module TaintFlowMake<
4748
private import TaintTrackingLang
4849
private import DF::DataFlowMake<Location, DataFlowLang> as DataFlow
4950
private import MakeImpl<Location, DataFlowLang> as DataFlowInternal
51+
private import MakeImplStage1<Location, DataFlowLang> as DataFlowInternalStage1
5052

5153
private module AddTaintDefaults<DataFlowInternal::FullStateConfigSig Config> implements
5254
DataFlowInternal::FullStateConfigSig
@@ -94,7 +96,13 @@ module TaintFlowMake<
9496
import AddTaintDefaults<Config0>
9597
}
9698

97-
import DataFlowInternal::Impl<C>
99+
private module Stage1 = DataFlowInternalStage1::ImplStage1<C>;
100+
101+
import Stage1::PartialFlow
102+
103+
private module Flow = DataFlowInternal::Impl<C, Stage1::Stage1NoState>;
104+
105+
import Flow
98106
}
99107

100108
/**
@@ -122,7 +130,13 @@ module TaintFlowMake<
122130
import AddTaintDefaults<Config0>
123131
}
124132

125-
import DataFlowInternal::Impl<C>
133+
private module Stage1 = DataFlowInternalStage1::ImplStage1<C>;
134+
135+
import Stage1::PartialFlow
136+
137+
private module Flow = DataFlowInternal::Impl<C, Stage1::Stage1WithState>;
138+
139+
import Flow
126140
}
127141

128142
signature int speculationLimitSig();
@@ -218,7 +232,13 @@ module TaintFlowMake<
218232
import AddTaintDefaults<AddSpeculativeTaintSteps<Config0, speculationLimit/0>>
219233
}
220234

221-
import DataFlowInternal::Impl<C>
235+
private module Stage1 = DataFlowInternalStage1::ImplStage1<C>;
236+
237+
import Stage1::PartialFlow
238+
239+
private module Flow = DataFlowInternal::Impl<C, Stage1::Stage1WithState>;
240+
241+
import Flow
222242
}
223243

224244
/**
@@ -250,6 +270,12 @@ module TaintFlowMake<
250270
import AddTaintDefaults<AddSpeculativeTaintSteps<Config0, speculationLimit/0>>
251271
}
252272

253-
import DataFlowInternal::Impl<C>
273+
private module Stage1 = DataFlowInternalStage1::ImplStage1<C>;
274+
275+
import Stage1::PartialFlow
276+
277+
private module Flow = DataFlowInternal::Impl<C, Stage1::Stage1WithState>;
278+
279+
import Flow
254280
}
255281
}

0 commit comments

Comments
 (0)