Skip to content

Commit a8214ce

Browse files
author
Max Schaefer
committed
JavaScript: Fix regexes for escaping schemes.
1 parent 5349e0f commit a8214ce

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ DataFlow::Node getASimplePredecessor(DataFlow::Node nd) {
5454
* into a form described by regular expression `regex`.
5555
*/
5656
predicate escapingScheme(string metachar, string regex) {
57-
metachar = "&" and regex = "&.*;"
57+
metachar = "&" and regex = "&.+;"
5858
or
59-
metachar = "%" and regex = "%.*"
59+
metachar = "%" and regex = "%.+"
6060
or
61-
metachar = "\\" and regex = "\\\\.*"
61+
metachar = "\\" and regex = "\\\\.+"
6262
}
6363

6464
/**

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
@@ -114,3 +114,12 @@ function encodeQuotes(s) {
114114
function badWrappedEncode2(s) {
115115
return encodeQuotes(s).replace(/&/g, "&");
116116
}
117+
118+
function roundtrip(s) {
119+
return JSON.parse(JSON.stringify(s));
120+
}
121+
122+
// dubious, but out of scope for this query
123+
function badRoundtrip(s) {
124+
return s.replace(/\\\\/g, "\\").replace(/\\/g, "\\\\");
125+
}

0 commit comments

Comments
 (0)