Skip to content

Commit f38e696

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: refactor to use ValidationMethod
1 parent 20705ca commit f38e696

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

java/ql/lib/semmle/code/java/security/PathSanitizer.qll

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,22 +353,26 @@ private class FileGetNameSanitizer extends PathInjectionSanitizer {
353353
}
354354
}
355355

356+
/** Holds if `g` is a guard that checks for `..` components. */
357+
private predicate pathTraversalGuard(Guard g, Expr e, boolean branch) {
358+
branch = g.(PathTraversalGuard).getBranch() and
359+
localTaintFlowToPathGuard(e, g)
360+
}
361+
356362
/**
357363
* A sanitizer that considers the second argument to a `File` constructor safe
358364
* if it is checked for `..` components (`PathTraversalGuard`) or if any internal
359365
* `..` components are removed from it (`PathNormalizeSanitizer`).
360366
*/
361367
private class FileConstructorSanitizer extends PathInjectionSanitizer {
362368
FileConstructorSanitizer() {
363-
exists(ConstructorCall constrCall, Argument arg, Expr guard |
369+
exists(ConstructorCall constrCall, Argument arg |
364370
constrCall.getConstructedType() instanceof TypeFile and
365371
arg = constrCall.getArgument(1) and
366372
(
367-
guard
368-
.(PathTraversalGuard)
369-
.controls(arg.getBasicBlock(), guard.(PathTraversalGuard).getBranch())
370-
or
371-
TaintTracking::localExprTaint(guard.(PathNormalizeSanitizer), arg)
373+
arg = DataFlow::BarrierGuard<pathTraversalGuard/3>::getABarrierNode().asExpr() or
374+
arg = ValidationMethod<pathTraversalGuard/3>::getAValidatedNode().asExpr() or
375+
TaintTracking::localExprTaint(any(PathNormalizeSanitizer p), arg)
372376
) and
373377
this.asExpr() = constrCall
374378
)

0 commit comments

Comments
 (0)