Skip to content

Commit 3e4e75c

Browse files
committed
C#: Re-factor XPathInjection to use the new API.
1 parent e6be88b commit 3e4e75c

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ abstract class Sink extends DataFlow::ExprNode { }
2424
abstract class Sanitizer extends DataFlow::ExprNode { }
2525

2626
/**
27+
* DEPRECATED: Use `XpathInjection` instead.
28+
*
2729
* A taint-tracking configuration for untrusted user input used in XPath expression.
2830
*/
29-
class TaintTrackingConfiguration extends TaintTracking::Configuration {
31+
deprecated class TaintTrackingConfiguration extends TaintTracking::Configuration {
3032
TaintTrackingConfiguration() { this = "XPathInjection" }
3133

3234
override predicate isSource(DataFlow::Node source) { source instanceof Source }
@@ -36,6 +38,32 @@ class TaintTrackingConfiguration extends TaintTracking::Configuration {
3638
override predicate isSanitizer(DataFlow::Node node) { node instanceof Sanitizer }
3739
}
3840

41+
/**
42+
* A taint-tracking configuration for untrusted user input used in XPath expression.
43+
*/
44+
module XpathInjectionConfig implements DataFlow::ConfigSig {
45+
/**
46+
* Holds if `source` is a relevant data flow source.
47+
*/
48+
predicate isSource(DataFlow::Node source) { source instanceof Source }
49+
50+
/**
51+
* Holds if `sink` is a relevant data flow sink.
52+
*/
53+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
54+
55+
/**
56+
* Holds if data flow through `node` is prohibited. This completely removes
57+
* `node` from the data flow graph.
58+
*/
59+
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
60+
}
61+
62+
/**
63+
* A taint-tracking module for untrusted user input used in XPath expression.
64+
*/
65+
module XpathInjection = TaintTracking::Global<XpathInjectionConfig>;
66+
3967
/** A source of remote user input. */
4068
class RemoteSource extends Source instanceof RemoteFlowSource { }
4169

csharp/ql/src/Security Features/CWE-643/StoredXPathInjection.ql

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@
1313

1414
import csharp
1515
import semmle.code.csharp.security.dataflow.flowsources.Stored
16-
import semmle.code.csharp.security.dataflow.XPathInjectionQuery as XPathInjection
17-
import semmle.code.csharp.dataflow.DataFlow::DataFlow::PathGraph
16+
import semmle.code.csharp.security.dataflow.XPathInjectionQuery
17+
import StoredXpathInjection::PathGraph
1818

19-
class StoredTaintTrackingConfiguration extends XPathInjection::TaintTrackingConfiguration {
20-
override predicate isSource(DataFlow::Node source) { source instanceof StoredFlowSource }
19+
module StoredXpathInjectionConfig implements DataFlow::ConfigSig {
20+
predicate isSource(DataFlow::Node source) { source instanceof StoredFlowSource }
21+
22+
predicate isSink = XpathInjectionConfig::isSink/1;
23+
24+
predicate isBarrier = XpathInjectionConfig::isBarrier/1;
2125
}
2226

23-
from StoredTaintTrackingConfiguration c, DataFlow::PathNode source, DataFlow::PathNode sink
24-
where c.hasFlowPath(source, sink)
27+
module StoredXpathInjection = TaintTracking::Global<StoredXpathInjectionConfig>;
28+
29+
from StoredXpathInjection::PathNode source, StoredXpathInjection::PathNode sink
30+
where StoredXpathInjection::flowPath(source, sink)
2531
select sink.getNode(), source, sink, "This XPath expression depends on a $@.", source.getNode(),
2632
"stored (potentially user-provided) value"

csharp/ql/src/Security Features/CWE-643/XPathInjection.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
import csharp
1515
import semmle.code.csharp.security.dataflow.XPathInjectionQuery
16-
import semmle.code.csharp.dataflow.DataFlow::DataFlow::PathGraph
16+
import XpathInjection::PathGraph
1717

18-
from TaintTrackingConfiguration c, DataFlow::PathNode source, DataFlow::PathNode sink
19-
where c.hasFlowPath(source, sink)
18+
from XpathInjection::PathNode source, XpathInjection::PathNode sink
19+
where XpathInjection::flowPath(source, sink)
2020
select sink.getNode(), source, sink, "This XPath expression depends on a $@.", source.getNode(),
2121
"user-provided value"

0 commit comments

Comments
 (0)