JS: Support regexp-based path traversal check

This commit is contained in:
Asger Feldthaus
2021-10-28 15:42:47 +02:00
parent 83edcf515b
commit 5f4c1dd19b
3 changed files with 18 additions and 27 deletions

View File

@@ -460,6 +460,24 @@ module TaintedPath {
}
}
/**
* An expression of form `x.matches(/\.\./)` or similar.
*/
class ContainsDotDotRegExpSanitizer extends BarrierGuardNode {
StringOps::RegExpTest test;
ContainsDotDotRegExpSanitizer() {
this = test and
test.getRegExp().getConstantValue() = [".", "..", "../"]
}
override predicate blocks(boolean outcome, Expr e, DataFlow::FlowLabel label) {
e = test.getStringOperand().asExpr() and
outcome = test.getPolarity().booleanNot() and
label.(Label::PosixPath).canContainDotDotSlash() // can still be bypassed by normalized absolute path
}
}
/**
* A sanitizer that recognizes the following pattern:
* ```