Skip to content

Commit 7837ad6

Browse files
Jami CogswellJami Cogswell
Jami Cogswell
authored and
Jami Cogswell
committed
Java: check for tainted parent arg
1 parent 343e3d2 commit 7837ad6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,19 @@ private predicate maybeNull(Expr expr) {
363363
)
364364
}
365365

366+
/** A taint-tracking configuration for reasoning about tainted nodes. */
367+
private module TaintedConfig implements DataFlow::ConfigSig {
368+
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }
369+
370+
predicate isSink(DataFlow::Node sink) { any() }
371+
}
372+
373+
/** Tracks flow from any `ActiveThreatModelSource` to any node. */
374+
private module TaintedFlow = TaintTracking::Global<TaintedConfig>;
375+
376+
/** Holds if `expr is tainted by an `ActiveThreatModelSource`. */
377+
private predicate isTainted(Expr expr) { TaintedFlow::flowToExpr(expr) }
378+
366379
/** Holds if `g` is a guard that checks for `..` components. */
367380
private predicate pathTraversalGuard(Guard g, Expr e, boolean branch) {
368381
branch = g.(PathTraversalGuard).getBranch() and
@@ -382,6 +395,7 @@ private class FileConstructorSanitizer extends PathInjectionSanitizer {
382395
// `java.io.File` documentation states that such cases are
383396
// treated as if invoking the single-argument `File` constructor.
384397
not maybeNull(constrCall.getArgument(0)) and
398+
not isTainted(constrCall.getArgument(0)) and
385399
arg = constrCall.getArgument(1) and
386400
(
387401
arg = DataFlow::BarrierGuard<pathTraversalGuard/3>::getABarrierNode().asExpr() or

0 commit comments

Comments
 (0)