@@ -18,12 +18,10 @@ private import semmle.code.csharp.dataflow.TaintTracking2
18
18
*/
19
19
predicate xssFlow ( XssNode source , XssNode sink , string message ) {
20
20
// standard taint-tracking
21
- exists (
22
- TaintTrackingConfiguration c , DataFlow2:: PathNode sourceNode , DataFlow2:: PathNode sinkNode
23
- |
21
+ exists ( XssTracking:: PathNode sourceNode , XssTracking:: PathNode sinkNode |
24
22
sourceNode = source .asDataFlowNode ( ) and
25
23
sinkNode = sink .asDataFlowNode ( ) and
26
- c . hasFlowPath ( sourceNode , sinkNode ) and
24
+ XssTracking :: flowPath ( sourceNode , sinkNode ) and
27
25
message =
28
26
"is written to HTML or JavaScript" +
29
27
any ( string explanation |
@@ -45,7 +43,7 @@ predicate xssFlow(XssNode source, XssNode sink, string message) {
45
43
module PathGraph {
46
44
/** Holds if `(pred,succ)` is an edge in the graph of data flow path explanations. */
47
45
query predicate edges ( XssNode pred , XssNode succ ) {
48
- exists ( DataFlow2 :: PathNode a , DataFlow2 :: PathNode b | DataFlow2 :: PathGraph:: edges ( a , b ) |
46
+ exists ( XssTracking :: PathNode a , XssTracking :: PathNode b | XssTracking :: PathGraph:: edges ( a , b ) |
49
47
pred .asDataFlowNode ( ) = a and
50
48
succ .asDataFlowNode ( ) = b
51
49
)
@@ -56,7 +54,7 @@ module PathGraph {
56
54
57
55
/** Holds if `n` is a node in the graph of data flow path explanations. */
58
56
query predicate nodes ( XssNode n , string key , string val ) {
59
- DataFlow2 :: PathGraph:: nodes ( n .asDataFlowNode ( ) , key , val )
57
+ XssTracking :: PathGraph:: nodes ( n .asDataFlowNode ( ) , key , val )
60
58
or
61
59
xssFlow ( n , n , _) and
62
60
key = "semmle.label" and
@@ -69,13 +67,13 @@ module PathGraph {
69
67
* `ret -> out` is summarized as the edge `arg -> out`.
70
68
*/
71
69
query predicate subpaths ( XssNode arg , XssNode par , XssNode ret , XssNode out ) {
72
- DataFlow2 :: PathGraph:: subpaths ( arg .asDataFlowNode ( ) , par . asDataFlowNode ( ) , ret .asDataFlowNode ( ) ,
73
- out .asDataFlowNode ( ) )
70
+ XssTracking :: PathGraph:: subpaths ( arg .asDataFlowNode ( ) , par .asDataFlowNode ( ) ,
71
+ ret . asDataFlowNode ( ) , out .asDataFlowNode ( ) )
74
72
}
75
73
}
76
74
77
75
private newtype TXssNode =
78
- TXssDataFlowNode ( DataFlow2 :: PathNode node ) or
76
+ TXssDataFlowNode ( XssTracking :: PathNode node ) or
79
77
TXssAspNode ( AspInlineMember m )
80
78
81
79
/**
@@ -90,21 +88,25 @@ class XssNode extends TXssNode {
90
88
/** Gets the location of this node. */
91
89
Location getLocation ( ) { none ( ) }
92
90
93
- /** Gets the data flow node corresponding to this node, if any. */
94
- DataFlow2:: PathNode asDataFlowNode ( ) { result = this .( XssDataFlowNode ) .getDataFlowNode ( ) }
91
+ /**
92
+ * Gets the data flow node corresponding to this node, if any.
93
+ */
94
+ XssTracking:: PathNode asDataFlowNode ( ) { result = this .( XssDataFlowNode ) .getDataFlowNode ( ) }
95
95
96
96
/** Gets the ASP inline code element corresponding to this node, if any. */
97
97
AspInlineMember asAspInlineMember ( ) { result = this .( XssAspNode ) .getAspInlineMember ( ) }
98
98
}
99
99
100
- /** A data flow node, viewed as an XSS flow node. */
100
+ /**
101
+ * A data flow node, viewed as an XSS flow node.
102
+ */
101
103
class XssDataFlowNode extends TXssDataFlowNode , XssNode {
102
- DataFlow2 :: PathNode node ;
104
+ XssTracking :: PathNode node ;
103
105
104
106
XssDataFlowNode ( ) { this = TXssDataFlowNode ( node ) }
105
107
106
108
/** Gets the data flow node corresponding to this node. */
107
- DataFlow2 :: PathNode getDataFlowNode ( ) { result = node }
109
+ XssTracking :: PathNode getDataFlowNode ( ) { result = node }
108
110
109
111
override string toString ( ) { result = node .toString ( ) }
110
112
@@ -136,9 +138,11 @@ abstract class Source extends DataFlow::Node { }
136
138
abstract class Sanitizer extends DataFlow:: ExprNode { }
137
139
138
140
/**
141
+ * DEPRECATED: Use `XssTracking` instead.
142
+ *
139
143
* A taint-tracking configuration for cross-site scripting (XSS) vulnerabilities.
140
144
*/
141
- class TaintTrackingConfiguration extends TaintTracking2:: Configuration {
145
+ deprecated class TaintTrackingConfiguration extends TaintTracking2:: Configuration {
142
146
TaintTrackingConfiguration ( ) { this = "XSSDataFlowConfiguration" }
143
147
144
148
override predicate isSource ( DataFlow:: Node source ) { source instanceof Source }
@@ -148,6 +152,29 @@ class TaintTrackingConfiguration extends TaintTracking2::Configuration {
148
152
override predicate isSanitizer ( DataFlow:: Node node ) { node instanceof Sanitizer }
149
153
}
150
154
155
+ /**
156
+ * A taint-tracking configuration for cross-site scripting (XSS) vulnerabilities.
157
+ */
158
+ module XssTrackingConfig implements DataFlow:: ConfigSig {
159
+ /**
160
+ * Holds if `source` is a relevant data flow source.
161
+ */
162
+ predicate isSource ( DataFlow:: Node source ) { source instanceof Source }
163
+
164
+ /**
165
+ * Holds if `sink` is a relevant data flow sink.
166
+ */
167
+ predicate isSink ( DataFlow:: Node sink ) { sink instanceof Sink }
168
+
169
+ /**
170
+ * Holds if data flow through `node` is prohibited. This completely removes
171
+ * `node` from the data flow graph.
172
+ */
173
+ predicate isBarrier ( DataFlow:: Node node ) { node instanceof Sanitizer }
174
+ }
175
+
176
+ module XssTracking = TaintTracking:: Global< XssTrackingConfig > ;
177
+
151
178
/** A source of remote user input. */
152
179
private class RemoteSource extends Source instanceof RemoteFlowSource { }
153
180
0 commit comments