Skip to content

Commit 448ed15

Browse files
committed
allow the empty string to flow to a JQuery XSS sink
1 parent 96896fd commit 448ed15

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/Xss.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ module DomBasedXss {
8080
not exists(DataFlow::Node prefix, string strval |
8181
isPrefixOfJQueryHtmlString(this, prefix) and
8282
strval = prefix.getStringValue() and
83+
not strval = "" and
8384
not strval.regexpMatch("\\s*<.*")
8485
) and
8586
not DOM::locationRef().flowsTo(this)

javascript/ql/test/query-tests/Security/CWE-079/XssThroughDom.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ nodes
4141
| xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name |
4242
| xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name |
4343
| xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name |
44+
| xss-through-dom.js:73:9:73:41 | selector |
45+
| xss-through-dom.js:73:20:73:41 | $("inpu ... 0).name |
46+
| xss-through-dom.js:73:20:73:41 | $("inpu ... 0).name |
47+
| xss-through-dom.js:77:7:77:14 | selector |
48+
| xss-through-dom.js:77:7:77:14 | selector |
4449
edges
4550
| xss-through-dom.js:2:16:2:34 | $("textarea").val() | xss-through-dom.js:2:16:2:34 | $("textarea").val() |
4651
| xss-through-dom.js:4:16:4:40 | $(".som ... .text() | xss-through-dom.js:4:16:4:40 | $(".som ... .text() |
@@ -56,6 +61,10 @@ edges
5661
| xss-through-dom.js:61:30:61:69 | $(docum ... value") | xss-through-dom.js:61:30:61:69 | $(docum ... value") |
5762
| xss-through-dom.js:64:30:64:40 | valMethod() | xss-through-dom.js:64:30:64:40 | valMethod() |
5863
| xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name | xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name |
64+
| xss-through-dom.js:73:9:73:41 | selector | xss-through-dom.js:77:7:77:14 | selector |
65+
| xss-through-dom.js:73:9:73:41 | selector | xss-through-dom.js:77:7:77:14 | selector |
66+
| xss-through-dom.js:73:20:73:41 | $("inpu ... 0).name | xss-through-dom.js:73:9:73:41 | selector |
67+
| xss-through-dom.js:73:20:73:41 | $("inpu ... 0).name | xss-through-dom.js:73:9:73:41 | selector |
5968
#select
6069
| xss-through-dom.js:2:16:2:34 | $("textarea").val() | xss-through-dom.js:2:16:2:34 | $("textarea").val() | xss-through-dom.js:2:16:2:34 | $("textarea").val() | Cross-site scripting vulnerability due to $@. | xss-through-dom.js:2:16:2:34 | $("textarea").val() | DOM text |
6170
| xss-through-dom.js:4:16:4:40 | $(".som ... .text() | xss-through-dom.js:4:16:4:40 | $(".som ... .text() | xss-through-dom.js:4:16:4:40 | $(".som ... .text() | Cross-site scripting vulnerability due to $@. | xss-through-dom.js:4:16:4:40 | $(".som ... .text() | DOM text |
@@ -71,3 +80,4 @@ edges
7180
| xss-through-dom.js:61:30:61:69 | $(docum ... value") | xss-through-dom.js:61:30:61:69 | $(docum ... value") | xss-through-dom.js:61:30:61:69 | $(docum ... value") | Cross-site scripting vulnerability due to $@. | xss-through-dom.js:61:30:61:69 | $(docum ... value") | DOM text |
7281
| xss-through-dom.js:64:30:64:40 | valMethod() | xss-through-dom.js:64:30:64:40 | valMethod() | xss-through-dom.js:64:30:64:40 | valMethod() | Cross-site scripting vulnerability due to $@. | xss-through-dom.js:64:30:64:40 | valMethod() | DOM text |
7382
| xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name | xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name | xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name | Cross-site scripting vulnerability due to $@. | xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name | DOM text |
83+
| xss-through-dom.js:77:7:77:14 | selector | xss-through-dom.js:73:20:73:41 | $("inpu ... 0).name | xss-through-dom.js:77:7:77:14 | selector | Cross-site scripting vulnerability due to $@. | xss-through-dom.js:73:20:73:41 | $("inpu ... 0).name | DOM text |

javascript/ql/test/query-tests/Security/CWE-079/xss-through-dom.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,10 @@
6969
}
7070

7171
$.jGrowl($("input").get(0).name); // NOT OK.
72+
73+
let selector = $("input").get(0).name;
74+
if (something()) {
75+
selector = $("textarea").val || ''
76+
}
77+
$(selector); // NOT OK
7278
})();

0 commit comments

Comments
 (0)