Skip to content

Commit 51a51d7

Browse files
authored
Merge pull request #2387 from max-schaefer/js/incomplete-dotdot-sanitization
Approved by asger-semmle
2 parents b39bcde + 5565be1 commit 51a51d7

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ where
166166
// URL encoder
167167
repl.getArgument(1).getStringValue().regexpMatch(urlEscapePattern)
168168
)
169+
or
170+
// path sanitizer
171+
(m = ".." or m = "/.." or m = "../" or m = "/../")
169172
) and
170173
// don't flag replace operations in a loop
171174
not DataFlow::valueNode(repl.getReceiver()) = DataFlow::valueNode(repl).getASuccessor+() and

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
| tst.js:148:2:148:10 | x.replace | This replaces only the first occurrence of "\\n". |
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 /'/. |
31+
| tst.js:202:10:202:18 | p.replace | This replaces only the first occurrence of "/../". |

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,7 @@ app.get('/some/path', function(req, res) {
197197
s.replace('"', '').replace('"', ''); // OK
198198
s.replace("'", "").replace("'", ""); // OK
199199
});
200+
201+
function bad18(p) {
202+
return p.replace("/../", ""); // NOT OK
203+
}

0 commit comments

Comments
 (0)