Skip to content

Commit de5c7ef

Browse files
committed
Added test case for unescape.
1 parent 40903a9 commit de5c7ef

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

javascript/ql/lib/semmle/javascript/dataflow/TaintTracking.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ module TaintTracking {
494494
succ = c and
495495
c =
496496
DataFlow::globalVarRef([
497-
"encodeURI", "decodeURI", "encodeURIComponent", "decodeURIComponent"
497+
"encodeURI", "decodeURI", "encodeURIComponent", "decodeURIComponent", "unescape"
498498
]).getACall() and
499499
pred = c.getArgument(0)
500500
)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
| tst.js:477:18:477:40 | locatio ... bstr(1) | tst.js:477:18:477:30 | location.hash | tst.js:477:18:477:40 | locatio ... bstr(1) | Cross-site scripting vulnerability due to $@. | tst.js:477:18:477:30 | location.hash | user-provided value |
224224
| tst.js:484:33:484:63 | decodeU ... n.hash) | tst.js:484:43:484:62 | window.location.hash | tst.js:484:33:484:63 | decodeU ... n.hash) | Cross-site scripting vulnerability due to $@. | tst.js:484:43:484:62 | window.location.hash | user-provided value |
225225
| tst.js:492:18:492:54 | target. ... "), '') | tst.js:491:16:491:39 | documen ... .search | tst.js:492:18:492:54 | target. ... "), '') | Cross-site scripting vulnerability due to $@. | tst.js:491:16:491:39 | documen ... .search | user-provided value |
226+
| tst.js:499:18:499:33 | unescape(source) | tst.js:498:16:498:26 | window.name | tst.js:499:18:499:33 | unescape(source) | Cross-site scripting vulnerability due to $@. | tst.js:498:16:498:26 | window.name | user-provided value |
226227
| typeahead.js:25:18:25:20 | val | typeahead.js:20:22:20:45 | documen ... .search | typeahead.js:25:18:25:20 | val | Cross-site scripting vulnerability due to $@. | typeahead.js:20:22:20:45 | documen ... .search | user-provided value |
227228
| v-html.vue:2:8:2:23 | v-html=tainted | v-html.vue:6:42:6:58 | document.location | v-html.vue:2:8:2:23 | v-html=tainted | Cross-site scripting vulnerability due to $@. | v-html.vue:6:42:6:58 | document.location | user-provided value |
228229
| various-concat-obfuscations.js:4:4:4:31 | "<div>" ... </div>" | various-concat-obfuscations.js:2:16:2:39 | documen ... .search | various-concat-obfuscations.js:4:4:4:31 | "<div>" ... </div>" | Cross-site scripting vulnerability due to $@. | various-concat-obfuscations.js:2:16:2:39 | documen ... .search | user-provided value |
@@ -745,6 +746,9 @@ edges
745746
| tst.js:491:7:491:39 | target | tst.js:492:18:492:23 | target | provenance | |
746747
| tst.js:491:16:491:39 | documen ... .search | tst.js:491:7:491:39 | target | provenance | |
747748
| tst.js:492:18:492:23 | target | tst.js:492:18:492:54 | target. ... "), '') | provenance | |
749+
| tst.js:498:7:498:26 | source | tst.js:499:27:499:32 | source | provenance | |
750+
| tst.js:498:16:498:26 | window.name | tst.js:498:7:498:26 | source | provenance | |
751+
| tst.js:499:27:499:32 | source | tst.js:499:18:499:33 | unescape(source) | provenance | |
748752
| typeahead.js:20:13:20:45 | target | typeahead.js:21:12:21:17 | target | provenance | |
749753
| typeahead.js:20:22:20:45 | documen ... .search | typeahead.js:20:13:20:45 | target | provenance | |
750754
| typeahead.js:21:12:21:17 | target | typeahead.js:24:30:24:32 | val | provenance | |
@@ -1397,6 +1401,10 @@ nodes
13971401
| tst.js:491:16:491:39 | documen ... .search | semmle.label | documen ... .search |
13981402
| tst.js:492:18:492:23 | target | semmle.label | target |
13991403
| tst.js:492:18:492:54 | target. ... "), '') | semmle.label | target. ... "), '') |
1404+
| tst.js:498:7:498:26 | source | semmle.label | source |
1405+
| tst.js:498:16:498:26 | window.name | semmle.label | window.name |
1406+
| tst.js:499:18:499:33 | unescape(source) | semmle.label | unescape(source) |
1407+
| tst.js:499:27:499:32 | source | semmle.label | source |
14001408
| typeahead.js:20:13:20:45 | target | semmle.label | target |
14011409
| typeahead.js:20:22:20:45 | documen ... .search | semmle.label | documen ... .search |
14021410
| typeahead.js:21:12:21:17 | target | semmle.label | target |

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,10 @@ nodes
607607
| tst.js:491:16:491:39 | documen ... .search | semmle.label | documen ... .search |
608608
| tst.js:492:18:492:23 | target | semmle.label | target |
609609
| tst.js:492:18:492:54 | target. ... "), '') | semmle.label | target. ... "), '') |
610+
| tst.js:498:7:498:26 | source | semmle.label | source |
611+
| tst.js:498:16:498:26 | window.name | semmle.label | window.name |
612+
| tst.js:499:18:499:33 | unescape(source) | semmle.label | unescape(source) |
613+
| tst.js:499:27:499:32 | source | semmle.label | source |
610614
| typeahead.js:9:28:9:30 | loc | semmle.label | loc |
611615
| typeahead.js:10:16:10:18 | loc | semmle.label | loc |
612616
| typeahead.js:20:13:20:45 | target | semmle.label | target |
@@ -1186,6 +1190,9 @@ edges
11861190
| tst.js:491:7:491:39 | target | tst.js:492:18:492:23 | target | provenance | |
11871191
| tst.js:491:16:491:39 | documen ... .search | tst.js:491:7:491:39 | target | provenance | |
11881192
| tst.js:492:18:492:23 | target | tst.js:492:18:492:54 | target. ... "), '') | provenance | |
1193+
| tst.js:498:7:498:26 | source | tst.js:499:27:499:32 | source | provenance | |
1194+
| tst.js:498:16:498:26 | window.name | tst.js:498:7:498:26 | source | provenance | |
1195+
| tst.js:499:27:499:32 | source | tst.js:499:18:499:33 | unescape(source) | provenance | |
11891196
| typeahead.js:9:28:9:30 | loc | typeahead.js:10:16:10:18 | loc | provenance | |
11901197
| typeahead.js:20:13:20:45 | target | typeahead.js:21:12:21:17 | target | provenance | |
11911198
| typeahead.js:20:22:20:45 | documen ... .search | typeahead.js:20:13:20:45 | target | provenance | |

javascript/ql/test/query-tests/Security/CWE-079/DomBasedXss/tst.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,8 @@ function nonGlobalSanitizer() {
493493
$("#foo").html(target.replace(new RegExp("<|>", unknownFlags()), '')); // OK - most likely good. We don't know what the flags are.
494494
$("#foo").html(target.replace(new RegExp("<|>", "g"), ''));
495495
}
496+
497+
function FooBar() {
498+
let source = window.name; // $ Source
499+
$('myId').html(unescape(source)) // $ Alert
500+
}

0 commit comments

Comments
 (0)