Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
C#: Slightly refactor 'CollectionFlow' tests to add a taint-flow test.
  • Loading branch information
MathiasVP committed Dec 12, 2025
commit b499661c05bdf7742ac7f5437e7d655d022d6843
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,25 @@ predicate defaultTaintSanitizer(DataFlow::Node node) {
)
}

/**
* Gets the (unbound) property `System.Collections.Generic.KeyValuePair.Value`.
*/
private Property keyValuePairValue() {
result.hasFullyQualifiedName("System.Collections.Generic", "KeyValuePair`2", "Value")
}

/**
* Holds if default `TaintTracking::Configuration`s should allow implicit reads
* of `c` at sinks and inputs to additional taint steps.
*/
bindingset[node]
predicate defaultImplicitTaintRead(DataFlow::Node node, DataFlow::ContentSet c) {
exists(node) and
c.isElement()
(
c.isElement()
or
c.isProperty(keyValuePairValue())
)
}

private class LocalTaintExprStepConfiguration extends ControlFlowReachabilityConfiguration {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,9 @@
* @kind path-problem
*/

import csharp
import CollectionFlowCommon
import utils.test.ProvenancePathGraph::ShowProvenance<ArrayFlow::PathNode, ArrayFlow::PathGraph>

module ArrayFlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node src) { src.asExpr() instanceof ObjectCreation }

predicate isSink(DataFlow::Node sink) {
exists(MethodCall mc |
mc.getTarget().hasUndecoratedName("Sink") and
mc.getAnArgument() = sink.asExpr()
)
}
}

module ArrayFlow = DataFlow::Global<ArrayFlowConfig>;

from ArrayFlow::PathNode source, ArrayFlow::PathNode sink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,10 @@ public void ReadOnlySpanConstructorFlow()
ReadOnlySpan<A> span = new ReadOnlySpan<A>(new[] { a });
Sink(span[0]); // flow
}

public void ImplicitMapValueRead(Dictionary<int, A> dict) {
var a = new A();
dict[0] = a;
Sink(dict); // no taint flow
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import csharp

module ArrayFlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node src) { src.asExpr() instanceof ObjectCreation }

predicate isSink(DataFlow::Node sink) {
exists(MethodCall mc |
mc.getTarget().hasUndecoratedName("Sink") and
mc.getAnArgument() = sink.asExpr()
)
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @kind path-problem
*/

import CollectionFlowCommon
import utils.test.ProvenancePathGraph::ShowProvenance<ArrayFlow::PathNode, ArrayFlow::PathGraph>

module ArrayFlow = TaintTracking::Global<ArrayFlowConfig>;

from ArrayFlow::PathNode source, ArrayFlow::PathNode sink
where ArrayFlow::flowPath(source, sink)
select source, source, sink, "$@", sink, sink.toString()