Skip to content

Commit 8ef7637

Browse files
Jami CogswellJami Cogswell
Jami Cogswell
authored and
Jami Cogswell
committed
Java: test perf with arg
1 parent 1a1a3a3 commit 8ef7637

File tree

2 files changed

+36
-43
lines changed

2 files changed

+36
-43
lines changed

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

+25-32
Original file line numberDiff line numberDiff line change
@@ -354,42 +354,35 @@ private class FileGetNameSanitizer extends PathInjectionSanitizer {
354354
}
355355

356356
/** Holds if `expr` may be null. */
357-
private predicate maybeNullArg(Expr expr) {
358-
exists(DataFlow::Node src, DataFlow::Node sink, ConstructorCall constrCall |
359-
constrCall.getConstructedType() instanceof TypeFile and
360-
constrCall.getNumArgument() = 2 and
361-
expr = constrCall.getArgument(0) and
357+
private predicate maybeNull(Expr expr) {
358+
exists(DataFlow::Node src, DataFlow::Node sink |
362359
src.asExpr() = nullExpr() and
363360
sink.asExpr() = expr
364361
|
365362
DataFlow::localFlow(src, sink)
366363
)
367364
}
368365

369-
/** A taint-tracking configuration for reasoning about tainted nodes. */
370-
private module TaintedConfig implements DataFlow::ConfigSig {
371-
predicate isSource(DataFlow::Node source) {
372-
source instanceof ActiveThreatModelSource
373-
or
374-
// ZipSlip uses ApiSourceNode instead of ActiveThreatModelSource
375-
source instanceof ApiSourceNode
376-
}
377-
378-
predicate isSink(DataFlow::Node sink) {
379-
exists(ConstructorCall constrCall |
380-
constrCall.getConstructedType() instanceof TypeFile and
381-
constrCall.getNumArgument() = 2 and
382-
sink.asExpr() = constrCall.getArgument(0)
383-
)
384-
}
385-
}
386-
387-
/** Tracks flow from any `ActiveThreatModelSource` to any node. */
388-
private module TaintedFlow = TaintTracking::Global<TaintedConfig>;
389-
390-
/** Holds if `expr is tainted by an `ActiveThreatModelSource`. */
391-
private predicate isTaintedArg(Expr expr) { TaintedFlow::flowToExpr(expr) }
392-
366+
// /** A taint-tracking configuration for reasoning about tainted nodes. */
367+
// private module TaintedConfig implements DataFlow::ConfigSig {
368+
// predicate isSource(DataFlow::Node source) {
369+
// source instanceof ActiveThreatModelSource
370+
// or
371+
// // ZipSlip uses ApiSourceNode instead of ActiveThreatModelSource
372+
// source instanceof ApiSourceNode
373+
// }
374+
// predicate isSink(DataFlow::Node sink) {
375+
// exists(ConstructorCall constrCall |
376+
// constrCall.getConstructedType() instanceof TypeFile and
377+
// constrCall.getNumArgument() = 2 and
378+
// sink.asExpr() = constrCall.getArgument(0)
379+
// )
380+
// }
381+
// }
382+
// /** Tracks flow from any `ActiveThreatModelSource` to any node. */
383+
// private module TaintedFlow = TaintTracking::Global<TaintedConfig>;
384+
// /** Holds if `expr is tainted by an `ActiveThreatModelSource`. */
385+
// private predicate isTaintedArg(Expr expr) { TaintedFlow::flowToExpr(expr) }
393386
/** Holds if `g` is a guard that checks for `..` components. */
394387
private predicate pathTraversalGuard(Guard g, Expr e, boolean branch) {
395388
branch = g.(PathTraversalGuard).getBranch() and
@@ -408,15 +401,15 @@ private class FileConstructorSanitizer extends PathInjectionSanitizer {
408401
// Exclude cases where the parent argument is null since the
409402
// `java.io.File` documentation states that such cases are
410403
// treated as if invoking the single-argument `File` constructor.
411-
not maybeNullArg(constrCall.getArgument(0)) and
412-
not isTaintedArg(constrCall.getArgument(0)) and
404+
not maybeNull(constrCall.getArgument(0)) and
405+
// not isTaintedArg(constrCall.getArgument(0)) and
413406
arg = constrCall.getArgument(1) and
414407
(
415408
arg = DataFlow::BarrierGuard<pathTraversalGuard/3>::getABarrierNode().asExpr() or
416409
arg = ValidationMethod<pathTraversalGuard/3>::getAValidatedNode().asExpr() or
417410
TaintTracking::localExprTaint(any(PathNormalizeSanitizer p), arg)
418411
) and
419-
this.asExpr() = constrCall
412+
this.asExpr() = arg
420413
)
421414
}
422415
}

java/ql/test/library-tests/pathsanitizer/Test.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public void fileConstructorSanitizer() throws Exception {
483483
if (!source.contains("..")) {
484484
File f2 = new File(f1, source);
485485
sink(f2); // Safe
486-
sink(source); // $ hasTaintFlow
486+
sink(source); // $ MISSING: hasTaintFlow
487487
} else {
488488
File f3 = new File(f1, source);
489489
sink(f3); // $ hasTaintFlow
@@ -502,9 +502,9 @@ public void fileConstructorSanitizer() throws Exception {
502502

503503
if (!source.contains("..")) {
504504
// `f2` is unsafe if `f1` is tainted
505-
File f2 = new File(f1Tainted, source);
505+
File f2 = new File((File) source(), source);
506506
sink(f2); // $ hasTaintFlow
507-
sink(source); // $ hasTaintFlow
507+
sink(source); // $ MISSING: hasTaintFlow
508508
} else {
509509
File f3 = new File(f1Tainted, source);
510510
sink(f3); // $ hasTaintFlow
@@ -531,7 +531,7 @@ public void fileConstructorSanitizer() throws Exception {
531531
if (source.indexOf("..") == -1) {
532532
File f2 = new File(f1, source);
533533
sink(f2); // Safe
534-
sink(source); // $ hasTaintFlow
534+
sink(source); // $ MISSING: hasTaintFlow
535535
} else {
536536
File f3 = new File(f1, source);
537537
sink(f3); // $ hasTaintFlow
@@ -548,7 +548,7 @@ public void fileConstructorSanitizer() throws Exception {
548548
} else {
549549
File f3 = new File(f1, source);
550550
sink(f3); // Safe
551-
sink(source); // $ hasTaintFlow
551+
sink(source); // $ MISSING: hasTaintFlow
552552
}
553553
}
554554
{
@@ -557,7 +557,7 @@ public void fileConstructorSanitizer() throws Exception {
557557
if (source.lastIndexOf("..") == -1) {
558558
File f2 = new File(f1, source);
559559
sink(f2); // Safe
560-
sink(source); // $ hasTaintFlow
560+
sink(source); // $ MISSING: hasTaintFlow
561561
} else {
562562
File f3 = new File(f1, source);
563563
sink(f3); // $ hasTaintFlow
@@ -571,7 +571,7 @@ public void fileConstructorSanitizer() throws Exception {
571571
fileConstructorValidation(source);
572572
File f2 = new File(f1, source);
573573
sink(f2); // Safe
574-
sink(source); // $ hasTaintFlow
574+
sink(source); // $ MISSING: hasTaintFlow
575575
}
576576
{
577577
String source = (String) source();
@@ -582,7 +582,7 @@ public void fileConstructorSanitizer() throws Exception {
582582
} else {
583583
File f2 = new File(f1, source);
584584
sink(f2); // Safe
585-
sink(source); // $ hasTaintFlow
585+
sink(source); // $ MISSING: hasTaintFlow
586586
}
587587
}
588588
// PathNormalizeSanitizer
@@ -593,7 +593,7 @@ public void fileConstructorSanitizer() throws Exception {
593593
File f2 = new File(f1, normalized);
594594
sink(f2); // Safe
595595
sink(source); // $ hasTaintFlow
596-
sink(normalized); // $ hasTaintFlow
596+
sink(normalized); // $ MISSING: hasTaintFlow
597597
}
598598
{
599599
File source = (File) source();
@@ -602,7 +602,7 @@ public void fileConstructorSanitizer() throws Exception {
602602
File f2 = new File(f1, normalized);
603603
sink(f2); // Safe
604604
sink(source); // $ hasTaintFlow
605-
sink(normalized); // $ hasTaintFlow
605+
sink(normalized); // $ MISSING: hasTaintFlow
606606
}
607607
{
608608
String source = (String) source();
@@ -611,7 +611,7 @@ public void fileConstructorSanitizer() throws Exception {
611611
File f2 = new File(f1, normalized);
612612
sink(f2); // Safe
613613
sink(source); // $ hasTaintFlow
614-
sink(normalized); // $ hasTaintFlow
614+
sink(normalized); // $ MISSING: hasTaintFlow
615615
}
616616
}
617617
}

0 commit comments

Comments
 (0)