Shared: Apply ShowProvenance in InlineFlowTest.qll

This commit is contained in:
Tom Hvitved
2024-08-07 13:14:58 +02:00
parent 0dfdee775b
commit f83df76928
9 changed files with 74 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ import csharp
private import codeql.dataflow.test.InlineFlowTest
private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific
private import semmle.code.csharp.dataflow.internal.TaintTrackingImplSpecific
private import semmle.code.csharp.dataflow.internal.ExternalFlow as ExternalFlow
private import internal.InlineExpectationsTestImpl
private module FlowTestImpl implements InputSig<Location, CsharpDataFlow> {
@@ -33,6 +34,8 @@ private module FlowTestImpl implements InputSig<Location, CsharpDataFlow> {
) and
exists(sink)
}
predicate interpretModelForTest = ExternalFlow::interpretModelForTest/2;
}
import InlineFlowTestMake<Location, CsharpDataFlow, CsharpTaintTracking, Impl, FlowTestImpl>

View File

@@ -7,6 +7,7 @@ import go
private import codeql.dataflow.test.InlineFlowTest
private import semmle.go.dataflow.internal.DataFlowImplSpecific
private import semmle.go.dataflow.internal.TaintTrackingImplSpecific
private import semmle.go.dataflow.ExternalFlow as ExternalFlow
private import internal.InlineExpectationsTestImpl
private module FlowTestImpl implements InputSig<Location, GoDataFlow> {
@@ -24,6 +25,8 @@ private module FlowTestImpl implements InputSig<Location, GoDataFlow> {
exists(src) and
result = "\"" + sink.toString() + "\""
}
predicate interpretModelForTest = ExternalFlow::interpretModelForTest/2;
}
import InlineFlowTestMake<Location, GoDataFlow, GoTaintTracking, Impl, FlowTestImpl>

View File

@@ -8,6 +8,7 @@ import semmle.code.java.dataflow.DataFlow
private import codeql.dataflow.test.InlineFlowTest
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific
private import semmle.code.java.dataflow.ExternalFlow as ExternalFlow
private import internal.InlineExpectationsTestImpl
private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
@@ -28,6 +29,8 @@ private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
exists(sink)
}
predicate interpretModelForTest = ExternalFlow::interpretModelForTest/2;
}
import InlineFlowTestMake<Location, JavaDataFlow, JavaTaintTracking, Impl, FlowTestImpl>

View File

@@ -8,6 +8,7 @@ import semmle.code.java.dataflow.DataFlow
private import codeql.dataflow.test.InlineFlowTest
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific
private import semmle.code.java.dataflow.ExternalFlow as ExternalFlow
private import internal.InlineExpectationsTestImpl
private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
@@ -28,6 +29,8 @@ private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
exists(sink)
}
predicate interpretModelForTest = ExternalFlow::interpretModelForTest/2;
}
import InlineFlowTestMake<Location, JavaDataFlow, JavaTaintTracking, Impl, FlowTestImpl>

View File

@@ -8,6 +8,7 @@ import semmle.code.java.dataflow.DataFlow
private import codeql.dataflow.test.InlineFlowTest
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific
private import semmle.code.java.dataflow.ExternalFlow as ExternalFlow
private import internal.InlineExpectationsTestImpl
private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
@@ -28,6 +29,8 @@ private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
exists(sink)
}
predicate interpretModelForTest = ExternalFlow::interpretModelForTest/2;
}
import InlineFlowTestMake<Location, JavaDataFlow, JavaTaintTracking, Impl, FlowTestImpl>

View File

@@ -45,3 +45,25 @@ extensible predicate typeModel(string type1, string type2, string path);
* Holds if `path` can be substituted for a token `TypeVar[name]`.
*/
extensible predicate typeVariableModel(string name, string path);
/**
* Holds if the given extension tuple `madId` should pretty-print as `model`.
*
* This predicate should only be used in tests.
*/
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
exists(string type, string path, string kind |
sourceModel(type, path, kind, madId) and
model = "Source: " + type + "; " + path + "; " + kind
)
or
exists(string type, string path, string kind |
sinkModel(type, path, kind, madId) and
model = "Sink: " + type + "; " + path + "; " + kind
)
or
exists(string type, string path, string input, string output, string kind |
summaryModel(type, path, input, output, kind, madId) and
model = "Summary: " + type + "; " + path + "; " + input + "; " + output + "; " + kind
)
}

View File

@@ -8,6 +8,7 @@ private import codeql.Locations
private import codeql.dataflow.test.InlineFlowTest
private import codeql.ruby.dataflow.internal.DataFlowImplSpecific
private import codeql.ruby.dataflow.internal.TaintTrackingImplSpecific
private import codeql.ruby.frameworks.data.internal.ApiGraphModelsExtensions as ApiGraphModelsExtensions
private import internal.InlineExpectationsTestImpl
private module FlowTestImpl implements InputSig<Location, RubyDataFlow> {
@@ -18,6 +19,8 @@ private module FlowTestImpl implements InputSig<Location, RubyDataFlow> {
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
exists(sink)
}
predicate interpretModelForTest = ApiGraphModelsExtensions::interpretModelForTest/2;
}
import InlineFlowTestMake<Location, RubyDataFlow, RubyTaintTracking, Impl, FlowTestImpl>

View File

@@ -38,6 +38,9 @@ signature module InputSig<LocationSig Location, DF::InputSig<Location> DataFlowL
bindingset[src, sink]
string getArgString(DataFlowLang::Node src, DataFlowLang::Node sink);
/** Holds if the given extension tuple `madId` should pretty-print as `model`. */
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model);
}
module InlineFlowTestMake<
@@ -51,6 +54,8 @@ module InlineFlowTestMake<
private module InlineExpectationsTest = IET::Make<Test>;
private import ProvenancePathGraph
module DefaultFlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlowLang::Node source) { Impl::defaultSource(source) }
@@ -66,13 +71,33 @@ module InlineFlowTestMake<
bindingset[src, sink]
signature string getArgStringSig(DataFlowLang::Node src, DataFlowLang::Node sink);
private module DataFlowGlobal<DataFlow::ConfigSig Config> {
private import DataFlow::Global<Config> as G
import G
module PathGraphNoInterpretModel = G::PathGraph;
module PathGraph =
ShowProvenance<Impl::interpretModelForTest/2, PathNode, PathGraphNoInterpretModel>;
}
private module TaintTrackingGlobal<DataFlow::ConfigSig Config> {
private import TaintTracking::Global<Config> as G
import G
module PathGraphNoInterpretModel = G::PathGraph;
module PathGraph =
ShowProvenance<Impl::interpretModelForTest/2, PathNode, PathGraphNoInterpretModel>;
}
module FlowTestArgString<
DataFlow::ConfigSig ValueFlowConfig, DataFlow::ConfigSig TaintFlowConfig,
getArgStringSig/2 getArgString>
{
module ValueFlow = DataFlow::Global<ValueFlowConfig>;
module ValueFlow = DataFlowGlobal<ValueFlowConfig>;
module TaintFlow = TaintTracking::Global<TaintFlowConfig>;
module TaintFlow = TaintTrackingGlobal<TaintFlowConfig>;
private predicate hasLocationInfo(DataFlowLang::Node node, Test::Location location) {
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
@@ -104,7 +129,11 @@ module InlineFlowTestMake<
}
import InlineExpectationsTest::MakeTest<InlineTest>
import DataFlow::MergePathGraph<ValueFlow::PathNode, TaintFlow::PathNode, ValueFlow::PathGraph, TaintFlow::PathGraph>
private import DataFlow::MergePathGraph<ValueFlow::PathNode, TaintFlow::PathNode, ValueFlow::PathGraphNoInterpretModel, TaintFlow::PathGraphNoInterpretModel> as Merged
import Merged
module PathGraph =
ShowProvenance<Impl::interpretModelForTest/2, Merged::PathNode, Merged::PathGraph>;
predicate flowPath(PathNode source, PathNode sink) {
ValueFlow::flowPath(source.asPathNode1(), sink.asPathNode1()) or

View File

@@ -65,13 +65,13 @@ private module TranslateModels<
/** Transforms a `PathGraph` by printing the provenance information. */
module ShowProvenance<
interpretModelForTestSig/2 interpretModelForTest, PathNodeSig PathNode,
DF::PathGraphSig<PathNode> PathGraph>
DF::PathGraphSig<PathNode> PathGraph> implements DF::PathGraphSig<PathNode>
{
private predicate provenance(string model) { PathGraph::edges(_, _, _, model) }
private module Models = TranslateModels<interpretModelForTest/2, provenance/1>;
query predicate models(int r, string model) { Models::models(r, model) }
additional query predicate models(int r, string model) { Models::models(r, model) }
query predicate edges(PathNode a, PathNode b, string key, string val) {
exists(string model |