Skip to content

Commit 82d463e

Browse files
authored
Merge pull request github#6718 from hvitved/csharp/xss-subpath
C#: Add `subpaths` predicate to XSS queries
2 parents 64507ab + 6d315a5 commit 82d463e

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ module PathGraph {
6262
key = "semmle.label" and
6363
val = n.(XssAspNode).toString()
6464
}
65+
66+
/**
67+
* Holds if `(arg, par, ret, out)` forms a subpath-tuple, that is, flow through
68+
* a subpath between `par` and `ret` with the connecting edges `arg -> par` and
69+
* `ret -> out` is summarized as the edge `arg -> out`.
70+
*/
71+
query predicate subpaths(XssNode arg, XssNode par, XssNode ret, XssNode out) {
72+
DataFlow2::PathGraph::subpaths(arg.asDataFlowNode(), par.asDataFlowNode(), ret.asDataFlowNode(),
73+
out.asDataFlowNode())
74+
}
6575
}
6676

6777
private newtype TXssNode =

csharp/ql/test/query-tests/Security Features/CWE-079/StoredXSS/XSS.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ nodes
4444
| script.aspx:12:1:12:14 | <%= ... %> | semmle.label | <%= ... %> |
4545
| script.aspx:16:1:16:34 | <%= ... %> | semmle.label | <%= ... %> |
4646
| script.aspx:20:1:20:41 | <%= ... %> | semmle.label | <%= ... %> |
47+
subpaths
4748
#select
4849
| XSS.cs:26:32:26:51 | call to method ToString | XSS.cs:25:48:25:62 | access to field categoryTextBox : TextBox | XSS.cs:26:32:26:51 | call to method ToString | $@ flows to here and is written to HTML or JavaScript. | XSS.cs:25:48:25:62 | access to field categoryTextBox : TextBox | User-provided value |
4950
| XSS.cs:27:29:27:48 | call to method ToString | XSS.cs:25:48:25:62 | access to field categoryTextBox : TextBox | XSS.cs:27:29:27:48 | call to method ToString | $@ flows to here and is written to HTML or JavaScript. | XSS.cs:25:48:25:62 | access to field categoryTextBox : TextBox | User-provided value |

csharp/ql/test/query-tests/Security Features/CWE-079/XSS/XSS.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ nodes
3434
| XSSAspNetCore.cs:72:51:72:65 | access to property Headers : IHeaderDictionary | semmle.label | access to property Headers : IHeaderDictionary |
3535
| XSSAspNetCore.cs:72:51:72:72 | access to indexer : StringValues | semmle.label | access to indexer : StringValues |
3636
| XSSAspNetCore.cs:72:51:72:72 | call to operator implicit conversion | semmle.label | call to operator implicit conversion |
37+
subpaths
3738
#select
3839
| XSSAspNet.cs:26:30:26:34 | access to local variable sayHi | XSSAspNet.cs:19:25:19:43 | access to property QueryString : NameValueCollection | XSSAspNet.cs:26:30:26:34 | access to local variable sayHi | $@ flows to here and is written to HTML or JavaScript: System.Web.WebPages.WebPage.WriteLiteral() method. | XSSAspNet.cs:19:25:19:43 | access to property QueryString : NameValueCollection | User-provided value |
3940
| XSSAspNet.cs:36:40:36:44 | access to local variable sayHi | XSSAspNet.cs:19:25:19:43 | access to property QueryString : NameValueCollection | XSSAspNet.cs:36:40:36:44 | access to local variable sayHi | $@ flows to here and is written to HTML or JavaScript: System.Web.WebPages.WebPage.WriteLiteralTo() method. | XSSAspNet.cs:19:25:19:43 | access to property QueryString : NameValueCollection | User-provided value |

0 commit comments

Comments
 (0)