Skip to content

Commit 4b3cf72

Browse files
committed
C#: Teach XPath injection query about XPathNavigator
1 parent 7f0181c commit 4b3cf72

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

csharp/ql/src/semmle/code/csharp/frameworks/system/xml/XPath.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ module SystemXmlXPath {
2121
class XPathExpression extends Class {
2222
XPathExpression() { this.hasName("XPathExpression") }
2323
}
24+
25+
/** The `System.Xml.XPath.XPathNavigator` class. */
26+
class XPathNavigator extends Class {
27+
XPathNavigator() { this.hasName("XPathNavigator") }
28+
29+
/** Gets a method that selects nodes. */
30+
csharp::Method getASelectMethod() {
31+
result = this.getAMethod() and result.getName().matches("Select%")
32+
}
33+
}
2434
}

csharp/ql/src/semmle/code/csharp/security/dataflow/XPathInjection.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ module XPathInjection {
6565
}
6666
}
6767

68+
/** The `xpath` argument to an `XPathNavigator.Select*(..)` call. */
69+
class XmlNavigatorSink extends Sink {
70+
XmlNavigatorSink() {
71+
this.getExpr() =
72+
any(SystemXmlXPath::XPathNavigator xmlNav)
73+
.getASelectMethod()
74+
.getACall()
75+
.getArgumentForName("xpath")
76+
}
77+
}
78+
6879
private class SimpleTypeSanitizer extends Sanitizer, SimpleTypeSanitizedExpr { }
6980

7081
private class GuidSanitizer extends Sanitizer, GuidSanitizedExpr { }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
edges
22
| XPathInjection.cs:12:27:12:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:16:33:16:136 | ... + ... |
33
| XPathInjection.cs:12:27:12:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:19:29:19:132 | ... + ... |
4+
| XPathInjection.cs:12:27:12:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:28:20:28:123 | ... + ... |
5+
| XPathInjection.cs:12:27:12:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:31:30:31:133 | ... + ... |
46
| XPathInjection.cs:13:27:13:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:16:33:16:136 | ... + ... |
57
| XPathInjection.cs:13:27:13:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:19:29:19:132 | ... + ... |
8+
| XPathInjection.cs:13:27:13:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:28:20:28:123 | ... + ... |
9+
| XPathInjection.cs:13:27:13:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:31:30:31:133 | ... + ... |
610
nodes
711
| XPathInjection.cs:12:27:12:49 | access to property QueryString : NameValueCollection | semmle.label | access to property QueryString : NameValueCollection |
812
| XPathInjection.cs:13:27:13:49 | access to property QueryString : NameValueCollection | semmle.label | access to property QueryString : NameValueCollection |
913
| XPathInjection.cs:16:33:16:136 | ... + ... | semmle.label | ... + ... |
1014
| XPathInjection.cs:19:29:19:132 | ... + ... | semmle.label | ... + ... |
15+
| XPathInjection.cs:28:20:28:123 | ... + ... | semmle.label | ... + ... |
16+
| XPathInjection.cs:31:30:31:133 | ... + ... | semmle.label | ... + ... |
1117
#select
1218
| XPathInjection.cs:16:33:16:136 | ... + ... | XPathInjection.cs:12:27:12:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:16:33:16:136 | ... + ... | $@ flows to here and is used in an XPath expression. | XPathInjection.cs:12:27:12:49 | access to property QueryString | User-provided value |
1319
| XPathInjection.cs:16:33:16:136 | ... + ... | XPathInjection.cs:13:27:13:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:16:33:16:136 | ... + ... | $@ flows to here and is used in an XPath expression. | XPathInjection.cs:13:27:13:49 | access to property QueryString | User-provided value |
1420
| XPathInjection.cs:19:29:19:132 | ... + ... | XPathInjection.cs:12:27:12:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:19:29:19:132 | ... + ... | $@ flows to here and is used in an XPath expression. | XPathInjection.cs:12:27:12:49 | access to property QueryString | User-provided value |
1521
| XPathInjection.cs:19:29:19:132 | ... + ... | XPathInjection.cs:13:27:13:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:19:29:19:132 | ... + ... | $@ flows to here and is used in an XPath expression. | XPathInjection.cs:13:27:13:49 | access to property QueryString | User-provided value |
22+
| XPathInjection.cs:28:20:28:123 | ... + ... | XPathInjection.cs:12:27:12:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:28:20:28:123 | ... + ... | $@ flows to here and is used in an XPath expression. | XPathInjection.cs:12:27:12:49 | access to property QueryString | User-provided value |
23+
| XPathInjection.cs:28:20:28:123 | ... + ... | XPathInjection.cs:13:27:13:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:28:20:28:123 | ... + ... | $@ flows to here and is used in an XPath expression. | XPathInjection.cs:13:27:13:49 | access to property QueryString | User-provided value |
24+
| XPathInjection.cs:31:30:31:133 | ... + ... | XPathInjection.cs:12:27:12:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:31:30:31:133 | ... + ... | $@ flows to here and is used in an XPath expression. | XPathInjection.cs:12:27:12:49 | access to property QueryString | User-provided value |
25+
| XPathInjection.cs:31:30:31:133 | ... + ... | XPathInjection.cs:13:27:13:49 | access to property QueryString : NameValueCollection | XPathInjection.cs:31:30:31:133 | ... + ... | $@ flows to here and is used in an XPath expression. | XPathInjection.cs:13:27:13:49 | access to property QueryString | User-provided value |

0 commit comments

Comments
 (0)