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: Support stateless isSink in StateConfigSigs #13851

Merged
merged 8 commits into from
Aug 4, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private module AddTaintDefaults<DataFlowInternal::FullStateConfigSig Config> imp
Config::allowImplicitRead(node, c)
or
(
Config::isSink(node) or
Config::isSink(node, _) or
Config::isAdditionalFlowStep(node, _) or
Config::isAdditionalFlowStep(node, _, _, _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private module AddTaintDefaults<DataFlowInternal::FullStateConfigSig Config> imp
Config::allowImplicitRead(node, c)
or
(
Config::isSink(node) or
Config::isSink(node, _) or
Config::isAdditionalFlowStep(node, _) or
Config::isAdditionalFlowStep(node, _, _, _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private module AddTaintDefaults<DataFlowInternal::FullStateConfigSig Config> imp
Config::allowImplicitRead(node, c)
or
(
Config::isSink(node) or
Config::isSink(node, _) or
Config::isAdditionalFlowStep(node, _) or
Config::isAdditionalFlowStep(node, _, _, _)
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/dataflow/internal/DataFlowImpl1.qll
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/dataflow/internal/DataFlowImpl2.qll
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private module AddTaintDefaults<DataFlowInternal::FullStateConfigSig Config> imp
Config::allowImplicitRead(node, c)
or
(
Config::isSink(node) or
Config::isSink(node, _) or
Config::isAdditionalFlowStep(node, _) or
Config::isAdditionalFlowStep(node, _, _, _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private module AddTaintDefaults<DataFlowInternal::FullStateConfigSig Config> imp
Config::allowImplicitRead(node, c)
or
(
Config::isSink(node) or
Config::isSink(node, _) or
Config::isAdditionalFlowStep(node, _) or
Config::isAdditionalFlowStep(node, _, _, _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private module AddTaintDefaults<DataFlowInternal::FullStateConfigSig Config> imp
Config::allowImplicitRead(node, c)
or
(
Config::isSink(node) or
Config::isSink(node, _) or
Config::isAdditionalFlowStep(node, _) or
Config::isAdditionalFlowStep(node, _, _, _)
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImpl1.qll
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
2 changes: 2 additions & 0 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImpl2.qll
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private module Config implements FullStateConfigSig {
getConfig(state).isSource(source) and getState(state) instanceof FlowStateEmpty
}

predicate isSink(Node sink) { none() }

predicate isSink(Node sink, FlowState state) {
getConfig(state).isSink(sink, getState(state))
or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private module AddTaintDefaults<DataFlowInternal::FullStateConfigSig Config> imp
Config::allowImplicitRead(node, c)
or
(
Config::isSink(node) or
Config::isSink(node, _) or
Config::isAdditionalFlowStep(node, _) or
Config::isAdditionalFlowStep(node, _, _, _)
Expand Down
4 changes: 4 additions & 0 deletions shared/dataflow/change-notes/2023-08-02-dataflow-isSink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: feature
---
* The `StateConfigSig` signature now supports a unary `isSink` predicate that does not specify the `FlowState` for which the given node is a sink. Instead, any `FlowState` is considered a valid `FlowState` for such a sink.
5 changes: 5 additions & 0 deletions shared/dataflow/codeql/dataflow/DataFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ module Configs<DataFlowParameter Lang> {
*/
predicate isSink(Node sink, FlowState state);

/**
* Holds if `sink` is a relevant data flow sink for any state.
*/
default predicate isSink(Node sink) { none() }

/**
* Holds if data flow through `node` is prohibited. This completely removes
* `node` from the data flow graph.
Expand Down
Loading