@@ -4,6 +4,7 @@ import java
4
4
import semmle.code.java.dataflow.TaintTracking
5
5
import semmle.code.java.security.PathSanitizer
6
6
private import semmle.code.java.dataflow.ExternalFlow
7
+ private import semmle.code.java.security.PathCreation
7
8
8
9
/**
9
10
* A method that returns the name of an archive entry.
@@ -40,5 +41,25 @@ module ZipSlipFlow = TaintTracking::Global<ZipSlipConfig>;
40
41
* A sink that represents a file creation, such as a file write, copy or move operation.
41
42
*/
42
43
private class FileCreationSink extends DataFlow:: Node {
43
- FileCreationSink ( ) { sinkNode ( this , "path-injection" ) }
44
+ FileCreationSink ( ) {
45
+ sinkNode ( this , "path-injection" ) and
46
+ not isPathCreation ( this )
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Holds if `sink` is a path creation node that doesn't imply a read/write filesystem operation.
52
+ * This is to avoid creating new spurious alerts, since `PathCreation` sinks weren't
53
+ * previosuly part of this query.
54
+ */
55
+ private predicate isPathCreation ( DataFlow:: Node sink ) {
56
+ exists ( PathCreation pc |
57
+ pc .getAnInput ( ) = sink .asExpr ( ) and
58
+ // exclude actual read/write operations included in `PathCreation`
59
+ not pc .( Call )
60
+ .getCallee ( )
61
+ .getDeclaringType ( )
62
+ .hasQualifiedName ( "java.io" ,
63
+ [ "FileInputStream" , "FileOutputStream" , "FileReader" , "FileWriter" ] )
64
+ )
44
65
}
0 commit comments