Skip to content

Commit fc79242

Browse files
committed
add tests
1 parent 559f03e commit fc79242

File tree

2 files changed

+32
-1
lines changed
  • javascript/ql/test/query-tests/Security

2 files changed

+32
-1
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,25 @@ function domMethods() {
466466
let cell = row.insertCell();
467467
cell.innerHTML = source; // NOT OK
468468
}
469+
470+
function urlStuff() {
471+
var url = document.location.search.substr(1);
472+
473+
$("<a>", {href: url}).appendTo("body"); // NOT OK - but not detected [INCONSISTENCY]
474+
$("#foo").attr("href", url); // NOT OK - but not detected [INCONSISTENCY]
475+
$("#foo").attr({href: url}); // NOT OK - but not detected [INCONSISTENCY]
476+
$("<img>", {src: url}).appendTo("body"); // NOT OK - but not detected [INCONSISTENCY]
477+
$("<a>", {href: win.location.href}).appendTo("body"); // OK
478+
479+
$("<img>", {src: "http://google.com/" + url}).appendTo("body"); // OK
480+
481+
$("<img>", {src: ["http://google.com", url].join("/")}).appendTo("body"); // OK
482+
483+
if (url.startsWith("https://")) {
484+
$("<img>", {src: url}).appendTo("body"); // OK
485+
} else {
486+
$("<img>", {src: url}).appendTo("body"); // NOT OK - but not detected [INCONSISTENCY]
487+
}
488+
489+
window.open(location.hash.substr(1)); // OK - any JavaScript is executed in another context
490+
}

javascript/ql/test/query-tests/Security/CWE-601/ClientSideUrlRedirect/tst13.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,13 @@ function quz() {
7272
var payload = history.location.hash.substr(1);
7373

7474
history.replace(payload); // NOT OK
75-
}
75+
}
76+
77+
function bar() {
78+
var url = document.location.search.substr(1);
79+
80+
$("<a>", {href: url}).appendTo("body"); // NOT OK - but not detected [INCONSISTENCY]
81+
$("#foo").attr("href", url); // NOT OK - but not detected [INCONSISTENCY]
82+
$("#foo").attr({href: url}); // NOT OK - but not detected [INCONSISTENCY]
83+
$("<img>", {src: url}).appendTo("body"); // NOT OK - but not detected [INCONSISTENCY]
84+
}

0 commit comments

Comments
 (0)