@@ -16,8 +16,8 @@ import DataFlow::PathGraph
1616
1717private class MethodFileSystemFileCreation extends Method {
1818 MethodFileSystemFileCreation ( ) {
19- getDeclaringType ( ) instanceof TypeFile and
20- hasName ( [ "mkdir" , "mkdirs" , "createNewFile" ] )
19+ this . getDeclaringType ( ) instanceof TypeFile and
20+ this . hasName ( [ "mkdir" , "mkdirs" , "createNewFile" ] )
2121 }
2222}
2323
@@ -58,7 +58,26 @@ private class FilesVulnerableCreationMethodAccess extends MethodAccess {
5858 m .hasName ( [ "write" , "newBufferedWriter" , "newOutputStream" ] )
5959 or
6060 m .hasName ( [ "createFile" , "createDirectory" , "createDirectories" ] ) and
61- getNumArgument ( ) = 1
61+ this .getNumArgument ( ) = 1
62+ or
63+ m .hasName ( "newByteChannel" ) and
64+ this .getNumArgument ( ) = 2
65+ )
66+ }
67+ }
68+
69+ /**
70+ * A call to a `File` method that create files/directories with a specific set of permissions explicitly set.
71+ * We can safely assume that any calls to these methods with explicit `PosixFilePermissions.asFileAttribute` contains a certain level of intentionality behind it.
72+ */
73+ private class FilesSanitiznignCreationMethodAccess extends MethodAccess {
74+ FilesSanitiznignCreationMethodAccess ( ) {
75+ exists ( Method m |
76+ m = this .getMethod ( ) and
77+ m .getDeclaringType ( ) .hasQualifiedName ( "java.nio.file" , "Files" )
78+ |
79+ m .hasName ( [ "createFile" , "createDirectory" , "createDirectories" ] ) and
80+ this .getNumArgument ( ) = 2
6281 )
6382 }
6483}
@@ -92,10 +111,16 @@ private class TempDirSystemGetPropertyToCreateConfig extends TaintTracking::Conf
92111 }
93112
94113 override predicate isSink ( DataFlow:: Node sink ) { sink instanceof FileCreationSink }
114+
115+ override predicate isSanitizer ( DataFlow:: Node sanitizer ) {
116+ exists ( FilesSanitiznignCreationMethodAccess sanitisingMethodAccess |
117+ sanitizer .asExpr ( ) = sanitisingMethodAccess .getArgument ( 0 )
118+ )
119+ }
95120}
96121
97122from DataFlow:: PathNode source , DataFlow:: PathNode sink , TempDirSystemGetPropertyToCreateConfig conf
98123where conf .hasFlowPath ( source , sink )
99- select source .getNode ( ) , source , sink ,
124+ select sink .getNode ( ) , source , sink ,
100125 "Local information disclosure vulnerability from $@ due to use of file or directory readable by other local users." ,
101126 source .getNode ( ) , "system temp directory"
0 commit comments