Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: feature
---
* Added the `AdditionalTaintStep` extension point (`semmle.code.csharp.dataflow.FlowSteps`). Extend this class to add additional taint steps that apply to all taint-tracking configurations.
20 changes: 20 additions & 0 deletions csharp/ql/lib/semmle/code/csharp/dataflow/FlowSteps.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Provides classes representing various flow steps for taint tracking.
*/

private import codeql.util.Unit
private import semmle.code.csharp.dataflow.DataFlow

/**
* A unit class for adding additional taint steps.
*
* Extend this class to add additional taint steps that should apply to all
* taint configurations.
*/
class AdditionalTaintStep extends Unit {
/**
* Holds if the step from `node1` to `node2` should be considered a taint
* step for all configurations.
*/
abstract predicate step(DataFlow::Node node1, DataFlow::Node node2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ private import csharp
private import TaintTrackingPublic
private import FlowSummaryImpl as FlowSummaryImpl
private import semmle.code.csharp.Caching
private import semmle.code.csharp.dataflow.FlowSteps
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
private import semmle.code.csharp.dispatch.Dispatch
Expand Down Expand Up @@ -172,6 +173,8 @@ private module Cached {
model = ""
or
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, false, model)
or
any(AdditionalTaintStep a).step(nodeFrom, nodeTo) and model = "AdditionalTaintStep"
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| Test.cs:13:35:13:45 | access to parameter taintSource | Test.cs:13:23:13:46 | call to method Step | AdditionalTaintStep |
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import csharp
import semmle.code.csharp.dataflow.FlowSteps
import semmle.code.csharp.dataflow.internal.TaintTrackingPrivate

/**
* A test-only additional taint step that treats calls to `Marker.Step` as
* propagating taint from the argument to the call result, to verify that
* `AdditionalTaintStep` subclasses are picked up by `defaultAdditionalTaintStep`.
*/
private class MarkerStepTaintStep extends AdditionalTaintStep {
override predicate step(DataFlow::Node node1, DataFlow::Node node2) {
exists(MethodCall mc |
mc.getTarget().hasName("Step") and
mc.getTarget().getDeclaringType().hasName("Marker")
|
node1.asExpr() = mc.getArgument(0) and
node2.asExpr() = mc
)
}
}

from DataFlow::Node src, DataFlow::Node sink, string model
where defaultAdditionalTaintStep(src, sink, model) and model = "AdditionalTaintStep"
select src, sink, model
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Marker
{
// A stand-in for a framework method that isn't otherwise understood by the
// taint-tracking library, whose taint behaviour is modelled by a test-only
// `AdditionalTaintStep` subclass instead.
public static object Step(object x) => new object();
}

class Test
{
void M(object taintSource)
{
var tainted = Marker.Step(taintSource);
Sink(tainted);
}

static void Sink(object o) { }
}
Loading