Skip to content

Commit 7923c9d

Browse files
author
Esben Sparre Andreasen
committed
JS: add tests for missing flow of regular expressions
1 parent 42d3012 commit 7923c9d

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
var escaped = raw.replace(/"/g, '\"');
2+
(function() {
3+
var indirect = /"/g;
4+
raw.replace(indirect, '\"');
5+
});

javascript/ql/test/query-tests/Security/CWE-116/DoubleEscaping/tst.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,12 @@ function badPercentEscape(s) {
6060
s = s.replace(/%/g, '%25');
6161
return s;
6262
}
63+
64+
function badEncode(s) {
65+
var indirect1 = /"/g;
66+
var indirect2 = /'/g;
67+
var indirect3 = /&/g;
68+
return s.replace(indirect1, """)
69+
.replace(indirect2, "'")
70+
.replace(indirect3, "&");
71+
}

javascript/ql/test/query-tests/Security/CWE-116/IncompleteSanitization/tst.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,8 @@ app.get('/some/path', function(req, res) {
163163
flowifyComments(untrusted);
164164
good11(untrusted);
165165
});
166+
167+
(function (s) {
168+
var indirect = /'/;
169+
return s.replace(indirect, ""); // NOT OK
170+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
// NOT OK
22
window.location = /.*redirect=([^&]*).*/.exec(document.location.href)[1];
3+
4+
(function(){
5+
var indirect = /.*redirect=([^&]*).*/;
6+
window.location = indirect.exec(document.location.href)[1];
7+
});

0 commit comments

Comments
 (0)