@@ -17,6 +17,7 @@ import semmle.code.java.dataflow.SSA
1717import semmle.code.java.dataflow.TaintTracking
1818import DataFlow
1919import PathGraph
20+ private import semmle.code.java.dataflow.ExternalFlow
2021
2122/**
2223 * A method that returns the name of an archive entry.
@@ -33,34 +34,6 @@ class ArchiveEntryNameMethod extends Method {
3334 }
3435}
3536
36- /**
37- * An expression that will be treated as the destination of a write.
38- */
39- class WrittenFileName extends Expr {
40- WrittenFileName ( ) {
41- // Constructors that write to their first argument.
42- exists ( ConstructorCall ctr | this = ctr .getArgument ( 0 ) |
43- exists ( Class c | ctr .getConstructor ( ) = c .getAConstructor ( ) |
44- c .hasQualifiedName ( "java.io" , "FileOutputStream" ) or
45- c .hasQualifiedName ( "java.io" , "RandomAccessFile" ) or
46- c .hasQualifiedName ( "java.io" , "FileWriter" )
47- )
48- )
49- or
50- // Methods that write to their n'th argument
51- exists ( MethodAccess call , int n | this = call .getArgument ( n ) |
52- call .getMethod ( ) .getDeclaringType ( ) .hasQualifiedName ( "java.nio.file" , "Files" ) and
53- (
54- call .getMethod ( ) .getName ( ) .regexpMatch ( "new.*Reader|newOutputStream|create.*" ) and n = 0
55- or
56- call .getMethod ( ) .hasName ( "copy" ) and n = 1
57- or
58- call .getMethod ( ) .hasName ( "move" ) and n = 1
59- )
60- )
61- }
62- }
63-
6437/**
6538 * Holds if `n1` to `n2` is a dataflow step that converts between `String`,
6639 * `File`, and `Path`.
@@ -151,7 +124,7 @@ class ZipSlipConfiguration extends TaintTracking::Configuration {
151124 source .asExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof ArchiveEntryNameMethod
152125 }
153126
154- override predicate isSink ( Node sink ) { sink . asExpr ( ) instanceof WrittenFileName }
127+ override predicate isSink ( Node sink ) { sinkNode ( sink , "create-file" ) }
155128
156129 override predicate isAdditionalTaintStep ( Node n1 , Node n2 ) {
157130 filePathStep ( n1 , n2 ) or fileTaintStep ( n1 , n2 )
0 commit comments