Skip to content

Commit 4cc76bd

Browse files
Make the additional flow steps generally applicible to all queries
1 parent 1bcde2d commit 4cc76bd

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/TaintTrackingPrivate.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ private import semmle.code.csharp.dispatch.Dispatch
99
private import semmle.code.csharp.commons.ComparisonTest
1010
private import cil
1111
private import dotnet
12-
// import `TaintedMember` definitions from other files to avoid potential reevaluation
12+
// import `TaintedMember` and `AdditionalTaintStep` definitions from other files to avoid potential reevaluation
1313
private import semmle.code.csharp.frameworks.JsonNET
1414
private import semmle.code.csharp.frameworks.WCF
15+
private import semmle.code.csharp.frameworks.Razor
1516
private import semmle.code.csharp.security.dataflow.flowsources.Remote
1617

1718
/**
@@ -160,6 +161,8 @@ private module Cached {
160161
nodeTo.(FlowSummaryNode).getSummaryNode(), false)
161162
or
162163
nodeTo = nodeFrom.(DataFlow::NonLocalJumpNode).getAJumpSuccessor(false)
164+
or
165+
any(AdditionalTaintStep step).step(nodeFrom, nodeTo)
163166
}
164167
}
165168

csharp/ql/lib/semmle/code/csharp/dataflow/internal/TaintTrackingPublic.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
private import csharp
22
private import TaintTrackingPrivate
3+
private import codeql.util.Unit
34

45
/**
56
* Holds if taint propagates from `source` to `sink` in zero or more local
@@ -20,4 +21,18 @@ predicate localExprTaint(Expr e1, Expr e2) {
2021
/** A member (property or field) that is tainted if its containing object is tainted. */
2122
abstract class TaintedMember extends AssignableMember { }
2223

24+
/**
25+
* A unit class for adding additional taint steps.
26+
*
27+
* Extend this class to add additional taint steps that should apply to all
28+
* taint configurations.
29+
*/
30+
class AdditionalTaintStep extends Unit {
31+
/**
32+
* Holds if the step from `node1` to `node2` should be considered a taint
33+
* step for all configurations.
34+
*/
35+
abstract predicate step(DataFlow::Node node1, DataFlow::Node node2);
36+
}
37+
2338
predicate localTaintStep = localTaintStepImpl/2;

csharp/ql/lib/semmle/code/csharp/security/dataflow/XSSFlowSteps.qll renamed to csharp/ql/lib/semmle/code/csharp/frameworks/Razor.qll

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
/** Definitions for additional flow steps for cross-site scripting (XSS) vulnerabilities. */
1+
/** Provides definitions and flow steps related to Razor pages. */
22

33
import csharp
44
private import codeql.util.Unit
55
private import codeql.util.FilePath
66
private import semmle.code.csharp.frameworks.microsoft.AspNetCore
77

8-
/**
9-
* A unit class for providing additional flow steps for cross-site scripting (XSS) vulnerabilities.
10-
* Extend to provide additional flow steps.
11-
*/
12-
class XssAdditionalFlowStep extends Unit {
13-
/** Holds if there is an additional dataflow step from `node1` to `node2`. */
14-
abstract predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2);
15-
}
16-
178
/** A call to the `View` method */
189
private class ViewCall extends MethodCall {
1910
ViewCall() { this.getTarget().hasQualifiedName("Microsoft.AspNetCore.Mvc", "Controller", "View") }
@@ -74,7 +65,7 @@ private class ViewCall extends MethodCall {
7465
}
7566

7667
/** A compiler-generated Razor page. */
77-
private class RazorPage extends Class {
68+
class RazorPage extends Class {
7869
AssemblyAttribute attr;
7970

8071
RazorPage() {
@@ -90,8 +81,8 @@ private class RazorPage extends Class {
9081
string getSourceFilepath() { result = attr.getArgument(2).(StringLiteral).getValue() }
9182
}
9283

93-
private class ViewCallFlowStep extends XssAdditionalFlowStep {
94-
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
84+
private class ViewCallFlowStep extends TaintTracking::AdditionalTaintStep {
85+
override predicate step(DataFlow::Node node1, DataFlow::Node node2) {
9586
exists(ViewCall vc, RazorPage rp, PropertyAccess modelProp |
9687
viewCallRefersToPage(vc, rp) and
9788
node1.asExpr() = vc.getModelArgument() and

csharp/ql/lib/semmle/code/csharp/security/dataflow/XSSQuery.qll

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import csharp
77
private import XSSSinks
8-
private import XSSFlowSteps
98
private import semmle.code.csharp.security.Sanitizers
109
private import semmle.code.csharp.security.dataflow.flowsources.Remote
1110
private import semmle.code.csharp.dataflow.DataFlow2
@@ -167,13 +166,6 @@ module XssTrackingConfig implements DataFlow::ConfigSig {
167166
*/
168167
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
169168

170-
/**
171-
* Holds if there is an additional dataflow step from `node1` to `node2`.
172-
*/
173-
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
174-
any(XssAdditionalFlowStep x).isAdditionalFlowStep(node1, node2)
175-
}
176-
177169
/**
178170
* Holds if data flow through `node` is prohibited. This completely removes
179171
* `node` from the data flow graph.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
category: minorAnalysis
33
---
4-
Additional flow steps have been added to the `cs/web/xss` query to track flow from a `View` call in an MVC controller to the corresponding Razor page.
4+
Additional flow steps to track flow from a `View` call in an MVC controller to the corresponding Razor page, which may result in additional results for queries such as `cs/web/xss`.

0 commit comments

Comments
 (0)