Skip to content

Commit a1d92bf

Browse files
author
Esben Sparre Andreasen
committed
JS: generalize js/incomplete-sanitization to handle ConstantString
1 parent a4b3b1e commit a1d92bf

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

javascript/ql/src/Security/CWE-116/IncompleteSanitization.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ string metachar() {
2525
string getAMatchedString(Expr e) {
2626
result = getAMatchedConstant(e.(RegExpLiteral).getRoot()).getValue()
2727
or
28-
result = e.(StringLiteral).getValue()
28+
result = e.getStringValue()
2929
}
3030

3131
/** Gets a constant matched by `t`. */

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
| tst.js:37:20:37:23 | /"/g | This does not backslash-escape the backslash character. |
1010
| tst.js:41:20:41:22 | "/" | This replaces only the first occurrence of "/". |
1111
| tst.js:45:20:45:24 | "%25" | This replaces only the first occurrence of "%25". |
12+
| tst.js:49:20:49:22 | `'` | This replaces only the first occurrence of `'`. |
13+
| tst.js:53:20:53:22 | "'" | This replaces only the first occurrence of "'". |
14+
| tst.js:57:20:57:22 | `'` | This replaces only the first occurrence of `'`. |
15+
| tst.js:61:20:61:27 | "'" + "" | This replaces only the first occurrence of "'" + "". |
16+
| tst.js:65:20:65:22 | "'" | This replaces only the first occurrence of "'". |
17+
| tst.js:69:20:69:27 | "'" + "" | This replaces only the first occurrence of "'" + "". |

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
@@ -45,6 +45,29 @@ function bad11(s) {
4545
return s.replace("%25", "%"); // NOT OK
4646
}
4747

48+
function bad12(s) {
49+
return s.replace(`'`, ""); // NOT OK
50+
}
51+
52+
function bad13(s) {
53+
return s.replace("'", ``); // NOT OK
54+
}
55+
56+
function bad14(s) {
57+
return s.replace(`'`, ``); // NOT OK
58+
}
59+
60+
function bad15(s) {
61+
return s.replace("'" + "", ""); // NOT OK
62+
}
63+
64+
function bad16(s) {
65+
return s.replace("'", "" + ""); // NOT OK
66+
}
67+
68+
function bad17(s) {
69+
return s.replace("'" + "", "" + ""); // NOT OK
70+
}
4871

4972
function good1(s) {
5073
while (s.indexOf("'") > 0)
@@ -120,6 +143,12 @@ app.get('/some/path', function(req, res) {
120143
bad9(untrusted);
121144
bad10(untrusted);
122145
bad11(untrusted);
146+
bad12(untrusted);
147+
bad13(untrusted);
148+
bad14(untrusted);
149+
bad15(untrusted);
150+
bad16(untrusted);
151+
bad17(untrusted);
123152

124153
good1(untrusted);
125154
good2(untrusted);

0 commit comments

Comments
 (0)