Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataflow: Refactor FlowState to be paired with Node #18633

Merged
merged 14 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions javascript/ql/src/Security/CWE-915/PrototypePollutingFunction.ql
Original file line number Diff line number Diff line change
Expand Up @@ -251,25 +251,19 @@ module PropNameTrackingConfig implements DataFlow::StateConfigSig {
node = DataFlow::MakeStateBarrierGuard<FlowState, BarrierGuard>::getABarrierNode(state)
}

predicate isAdditionalFlowStep(
DataFlow::Node node1, FlowState state1, DataFlow::Node node2, FlowState state2
) {
exists(state1) and
state2 = state1 and
(
// Step through `p -> x[p]`
exists(DataFlow::PropRead read |
node1 = read.getPropertyNameExpr().flow() and
not read.(DynamicPropRead).hasDominatingAssignment() and
node2 = read
)
or
// Step through `x -> x[p]`
exists(DynamicPropRead read |
not read.hasDominatingAssignment() and
node1 = read.getBase() and
node2 = read
)
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
// Step through `p -> x[p]`
exists(DataFlow::PropRead read |
node1 = read.getPropertyNameExpr().flow() and
not read.(DynamicPropRead).hasDominatingAssignment() and
node2 = read
)
or
// Step through `x -> x[p]`
exists(DynamicPropRead read |
not read.hasDominatingAssignment() and
node1 = read.getBase() and
node2 = read
)
}

Expand Down
17 changes: 15 additions & 2 deletions shared/dataflow/codeql/dataflow/DataFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ private module PathGraphSigMod {
module DataFlowMake<LocationSig Location, InputSig<Location> Lang> {
private import Lang
private import internal.DataFlowImpl::MakeImpl<Location, Lang>
private import internal.DataFlowImplStage1::MakeImplStage1<Location, Lang>
import Configs<Location, Lang>

/**
Expand Down Expand Up @@ -700,7 +701,13 @@ module DataFlowMake<LocationSig Location, InputSig<Location> Lang> {
}
}

import Impl<C>
private module Stage1 = ImplStage1<C>;

import Stage1::PartialFlow

private module Flow = Impl<C, Stage1::Stage1NoState>;

import Flow
}

/**
Expand All @@ -723,7 +730,13 @@ module DataFlowMake<LocationSig Location, InputSig<Location> Lang> {
}
}

import Impl<C>
private module Stage1 = ImplStage1<C>;

import Stage1::PartialFlow

private module Flow = Impl<C, Stage1::Stage1WithState>;

import Flow
}

signature class PathNodeSig {
Expand Down
34 changes: 30 additions & 4 deletions shared/dataflow/codeql/dataflow/TaintTracking.qll
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

private import DataFlow as DF
private import internal.DataFlowImpl
private import internal.DataFlowImplStage1
private import codeql.util.Location

/**
Expand Down Expand Up @@ -47,6 +48,7 @@ module TaintFlowMake<
private import TaintTrackingLang
private import DF::DataFlowMake<Location, DataFlowLang> as DataFlow
private import MakeImpl<Location, DataFlowLang> as DataFlowInternal
private import MakeImplStage1<Location, DataFlowLang> as DataFlowInternalStage1

private module AddTaintDefaults<DataFlowInternal::FullStateConfigSig Config> implements
DataFlowInternal::FullStateConfigSig
Expand Down Expand Up @@ -94,7 +96,13 @@ module TaintFlowMake<
import AddTaintDefaults<Config0>
}

import DataFlowInternal::Impl<C>
private module Stage1 = DataFlowInternalStage1::ImplStage1<C>;

import Stage1::PartialFlow

private module Flow = DataFlowInternal::Impl<C, Stage1::Stage1NoState>;

import Flow
}

/**
Expand Down Expand Up @@ -122,7 +130,13 @@ module TaintFlowMake<
import AddTaintDefaults<Config0>
}

import DataFlowInternal::Impl<C>
private module Stage1 = DataFlowInternalStage1::ImplStage1<C>;

import Stage1::PartialFlow

private module Flow = DataFlowInternal::Impl<C, Stage1::Stage1WithState>;

import Flow
}

signature int speculationLimitSig();
Expand Down Expand Up @@ -218,7 +232,13 @@ module TaintFlowMake<
import AddTaintDefaults<AddSpeculativeTaintSteps<Config0, speculationLimit/0>>
}

import DataFlowInternal::Impl<C>
private module Stage1 = DataFlowInternalStage1::ImplStage1<C>;

import Stage1::PartialFlow

private module Flow = DataFlowInternal::Impl<C, Stage1::Stage1WithState>;

import Flow
}

/**
Expand Down Expand Up @@ -250,6 +270,12 @@ module TaintFlowMake<
import AddTaintDefaults<AddSpeculativeTaintSteps<Config0, speculationLimit/0>>
}

import DataFlowInternal::Impl<C>
private module Stage1 = DataFlowInternalStage1::ImplStage1<C>;

import Stage1::PartialFlow

private module Flow = DataFlowInternal::Impl<C, Stage1::Stage1WithState>;

import Flow
}
}
Loading