Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61aa075

Browse files
author
Max Schaefer
committed
JavaScript: Fix regexes for escaping schemes.
1 parent 4f899a9 commit 61aa075

2 files changed

Lines changed: 8 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@ function badEncodeWithReplacer(s) {
7878
};
7979
return s.replace(/["']/g, (c) => repl[c]).replace(/&/g, "&");
8080
}
81+
82+
// dubious, but out of scope for this query
83+
function badRoundtrip(s) {
84+
return s.replace(/\\\\/g, "\\").replace(/\\/g, "\\\\");
85+
}

0 commit comments

Comments
 (0)