Skip to content

Commit 7631803

Browse files
committed
JS: Add test cases for RegExp object usage in replace within incomplete sanitization
1 parent 9c2366a commit 7631803

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

javascript/ql/test/query-tests/Security/CWE-116/IncompleteSanitization/IncompleteMultiCharacterSanitization.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@
3939
| tst-multi-character-sanitization.js:145:13:145:90 | content ... /g, '') | This string may still contain $@, which may cause an HTML element injection vulnerability. | tst-multi-character-sanitization.js:145:30:145:30 | < | <script |
4040
| tst-multi-character-sanitization.js:148:3:148:99 | n.clone ... gi, '') | This string may still contain $@, which may cause an HTML element injection vulnerability. | tst-multi-character-sanitization.js:148:41:148:41 | < | <script |
4141
| tst-multi-character-sanitization.js:152:3:152:99 | n.clone ... gi, '') | This string may still contain $@, which may cause an HTML element injection vulnerability. | tst-multi-character-sanitization.js:152:41:152:41 | < | <script |
42+
| tst.js:341:9:341:44 | p.repla ... "), "") | This string may still contain $@, which may cause a path injection vulnerability. | tst.js:341:31:341:33 | \\. | ../ |

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,32 @@ function typicalBadHtmlSanitizers(s) {
336336
function typicalBadHtmlSanitizers(s) {
337337
s().replace(new RegExp("[<>]", unknown()),''); // NOT OK
338338
}
339+
340+
function bad18NewRegExp(p) {
341+
return p.replace(new RegExp("\\.\\./"), ""); // NOT OK -- should be flagged, but currently checking only for literals
342+
}
343+
344+
function bad4NewRegExpG(s) {
345+
return s.replace(new RegExp("\'","g"), "\\$&"); // NOT OK -- should be flagged, but currently checking only for literals
346+
}
347+
348+
function bad4NewRegExp(s) {
349+
return s.replace(new RegExp("\'"), "\\$&"); // NOT OK -- should be flagged, but currently checking only for literals
350+
}
351+
352+
function bad4NewRegExpUnknown(s) {
353+
return s.replace(new RegExp("\'", unknownFlags()), "\\$&"); // NOT OK -- should be flagged, but currently checking only for literals
354+
}
355+
356+
function newlinesNewReGexp(s) {
357+
require("child_process").execSync("which emacs").toString().replace(new RegExp("\n"), ""); // OK
358+
359+
x.replace(new RegExp("\n", "g"), "").replace(x, y); // OK
360+
x.replace(x, y).replace(new RegExp("\n", "g"), ""); // OK
361+
362+
x.replace(new RegExp("\n"), "").replace(x, y); // NOT OK -- should be flagged, but currently checking only for literals
363+
x.replace(x, y).replace(new RegExp("\n"), ""); // NOT OK -- should be flagged, but currently checking only for literals
364+
365+
x.replace(new RegExp("\n", unknownFlags()), "").replace(x, y); // OK
366+
x.replace(x, y).replace(new RegExp("\n", unknownFlags()), ""); // OK
367+
}

0 commit comments

Comments
 (0)