Skip to content

Commit d9d304f

Browse files
authored
Merge pull request #7076 from asgerf/js/tainted-path-regexp-guard2
Approved by erik-krogh
2 parents d9e02e8 + f14f944 commit d9d304f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

javascript/ql/lib/semmle/javascript/security/dataflow/TaintedPathCustomizations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ module TaintedPath {
459459
* An expression of form `x.matches(/\.\./)` or similar.
460460
*/
461461
class ContainsDotDotRegExpSanitizer extends BarrierGuardNode instanceof StringOps::RegExpTest {
462-
ContainsDotDotRegExpSanitizer() { super.getRegExp().getConstantValue() = [".", "..", "../"] }
462+
ContainsDotDotRegExpSanitizer() { super.getRegExp().getAMatchedString() = [".", "..", "../"] }
463463

464464
override predicate blocks(boolean outcome, Expr e, DataFlow::FlowLabel label) {
465465
e = super.getStringOperand().asExpr() and

javascript/ql/test/query-tests/Security/CWE-022/TaintedPath/normalizedPaths.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,7 @@ app.get('/dotdot-regexp', (req, res) => {
398398
if (!path.match(/\.\.\/foo/)) {
399399
fs.readFileSync(path); // NOT OK
400400
}
401+
if (!path.match(/(\.\.\/|\.\.\\)/)) {
402+
fs.readFileSync(path); // OK
403+
}
401404
});

0 commit comments

Comments
 (0)