Skip to content

Commit

Permalink
Java: check for tainted parent arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Jami Cogswell authored and Jami Cogswell committed Jan 31, 2025
1 parent 343e3d2 commit 7837ad6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions java/ql/lib/semmle/code/java/security/PathSanitizer.qll
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,19 @@ private predicate maybeNull(Expr expr) {
)
}

/** A taint-tracking configuration for reasoning about tainted nodes. */
private module TaintedConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }

predicate isSink(DataFlow::Node sink) { any() }
}

/** Tracks flow from any `ActiveThreatModelSource` to any node. */
private module TaintedFlow = TaintTracking::Global<TaintedConfig>;

/** Holds if `expr is tainted by an `ActiveThreatModelSource`. */
private predicate isTainted(Expr expr) { TaintedFlow::flowToExpr(expr) }

/** Holds if `g` is a guard that checks for `..` components. */
private predicate pathTraversalGuard(Guard g, Expr e, boolean branch) {
branch = g.(PathTraversalGuard).getBranch() and
Expand All @@ -382,6 +395,7 @@ private class FileConstructorSanitizer extends PathInjectionSanitizer {
// `java.io.File` documentation states that such cases are
// treated as if invoking the single-argument `File` constructor.
not maybeNull(constrCall.getArgument(0)) and
not isTainted(constrCall.getArgument(0)) and
arg = constrCall.getArgument(1) and
(
arg = DataFlow::BarrierGuard<pathTraversalGuard/3>::getABarrierNode().asExpr() or
Expand Down

0 comments on commit 7837ad6

Please sign in to comment.