Skip to content

Commit 98fd977

Browse files
committed
JS: imcomplete sanization now handles properly maybe global
1 parent 1ae1748 commit 98fd977

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ predicate isSimpleAlt(RegExpAlt t) { forall(RegExpTerm ch | ch = t.getAChild() |
5353
* regular expression and `new` prefixes the matched string with a backslash.
5454
*/
5555
predicate isBackslashEscape(StringReplaceCall mce, DataFlow::RegExpCreationNode re) {
56-
mce.isGlobal() and
56+
mce.maybeGlobal() and
5757
re = mce.getRegExp() and
5858
(
5959
// replacement with `\$&`, `\$1` or similar
@@ -147,7 +147,7 @@ from StringReplaceCall repl, DataFlow::Node old, string msg
147147
where
148148
(old = repl.getArgument(0) or old = repl.getRegExp()) and
149149
(
150-
not repl.isGlobal() and
150+
not repl.maybeGlobal() and
151151
msg = "This replaces only the first occurrence of " + old + "." and
152152
// only flag if this is likely to be a sanitizer or URL encoder or decoder
153153
exists(string m | m = getAMatchedString(old) |

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@
2929
| tst.js:149:2:149:24 | x.repla ... replace | This replaces only the first occurrence of "\\n". |
3030
| tst.js:193:9:193:17 | s.replace | This replaces only the first occurrence of /'/. |
3131
| tst.js:202:10:202:18 | p.replace | This replaces only the first occurrence of "/../". |
32-
| tst.js:337:2:337:12 | s().replace | This replaces only the first occurrence of new Reg ... nown()). |
3332
| tst.js:341:9:341:17 | p.replace | This replaces only the first occurrence of new Reg ... .\\\\./"). |
3433
| tst.js:345:9:345:17 | s.replace | This does not escape backslash characters in the input. |
3534
| tst.js:349:9:349:17 | s.replace | This replaces only the first occurrence of new RegExp("\\'"). |
36-
| tst.js:353:9:353:17 | s.replace | This replaces only the first occurrence of new Reg ... lags()). |
35+
| tst.js:353:9:353:17 | s.replace | This does not escape backslash characters in the input. |
3736
| tst.js:362:2:362:10 | x.replace | This replaces only the first occurrence of new RegExp("\\n"). |
3837
| tst.js:363:2:363:24 | x.repla ... replace | This replaces only the first occurrence of new RegExp("\\n"). |
39-
| tst.js:365:2:365:10 | x.replace | This replaces only the first occurrence of new Reg ... lags()). |
40-
| tst.js:366:2:366:24 | x.repla ... replace | This replaces only the first occurrence of new Reg ... lags()). |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,6 @@ function newlinesNewReGexp(s) {
362362
x.replace(new RegExp("\n"), "").replace(x, y); // NOT OK
363363
x.replace(x, y).replace(new RegExp("\n"), ""); // NOT OK
364364

365-
x.replace(new RegExp("\n", unknownFlags()), "").replace(x, y); // OK -- Should not be flagged but now it is
366-
x.replace(x, y).replace(new RegExp("\n", unknownFlags()), ""); // OK -- Should not be flagged but now it is
365+
x.replace(new RegExp("\n", unknownFlags()), "").replace(x, y); // OK
366+
x.replace(x, y).replace(new RegExp("\n", unknownFlags()), ""); // OK
367367
}

0 commit comments

Comments
 (0)