@@ -17,53 +17,68 @@ import semmle.code.java.dataflow.TaintTracking2
17
17
private import semmle.code.java.dataflow.ExternalFlow
18
18
import DataFlow:: PathGraph
19
19
20
+ /** A string literal that represents the MIME type for Android APKs. */
20
21
class PackageArchiveMimeTypeLiteral extends StringLiteral {
21
22
PackageArchiveMimeTypeLiteral ( ) { this .getValue ( ) = "application/vnd.android.package-archive" }
22
23
}
23
24
25
+ /** A method that sets the MIME type of an intent. */
24
26
class SetTypeMethod extends Method {
25
27
SetTypeMethod ( ) {
26
28
this .hasName ( [ "setType" , "setTypeAndNormalize" ] ) and
27
29
this .getDeclaringType ( ) instanceof TypeIntent
28
30
}
29
31
}
30
32
33
+ /** A method that sets the data URI and the MIME type of an intent. */
31
34
class SetDataAndTypeMethod extends Method {
32
35
SetDataAndTypeMethod ( ) {
33
36
this .hasName ( [ "setDataAndType" , "setDataAndTypeAndNormalize" ] ) and
34
37
this .getDeclaringType ( ) instanceof TypeIntent
35
38
}
36
39
}
37
40
41
+ /** A method that sets the data URI of an intent. */
38
42
class SetDataMethod extends Method {
39
43
SetDataMethod ( ) {
40
44
this .hasName ( [ "setData" , "setDataAndNormalize" , "setDataAndType" , "setDataAndTypeAndNormalize" ] ) and
41
45
this .getDeclaringType ( ) instanceof TypeIntent
42
46
}
43
47
}
44
48
49
+ /** A dataflow sink for the URI of an intent. */
45
50
class SetDataSink extends DataFlow:: ExprNode {
46
51
SetDataSink ( ) { this .getExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof SetDataMethod }
47
52
}
48
53
54
+ /** A method that generates a URI. */
49
55
class UriConstructorMethod extends Method {
50
56
UriConstructorMethod ( ) {
51
- this .hasQualifiedName ( "android.net" , "Uri" , [ "parse" , "fromFile" , "fromParts" ] )
57
+ this .hasQualifiedName ( "android.net" , "Uri" , [ "parse" , "fromFile" , "fromParts" ] ) or
58
+ this .hasQualifiedName ( "androidx.core.content" , "FileProvider" , "getUriForFile" )
52
59
}
53
60
}
54
61
55
- class ExternalSource extends DataFlow:: Node {
56
- ExternalSource ( ) {
62
+ /**
63
+ * A dataflow source representing the URIs which an APK not controlled by the
64
+ * application may come from. Incuding external storage and web URLs.
65
+ */
66
+ class ExternalAPKSource extends DataFlow:: Node {
67
+ ExternalAPKSource ( ) {
57
68
sourceNode ( this , "android-external-storage-dir" ) or
58
69
this .asExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof UriConstructorMethod or
59
70
this .asExpr ( ) .( StringLiteral ) .getValue ( ) .matches ( [ "file://%" , "http://%" , "https://%" ] )
60
71
}
61
72
}
62
73
63
- class ExternalSourceConfiguration extends DataFlow:: Configuration {
64
- ExternalSourceConfiguration ( ) { this = "ExternalSourceConfiguration" }
74
+ /**
75
+ * A dataflow configuration for flow from an external source of an APK to the
76
+ * `setData[AndType][AndNormalize]` method of an intent.
77
+ */
78
+ class APKConfiguration extends DataFlow:: Configuration {
79
+ APKConfiguration ( ) { this = "APKConfiguration" }
65
80
66
- override predicate isSource ( DataFlow:: Node node ) { node instanceof ExternalSource }
81
+ override predicate isSource ( DataFlow:: Node node ) { node instanceof ExternalAPKSource }
67
82
68
83
override predicate isSink ( DataFlow:: Node node ) {
69
84
exists ( MethodAccess ma |
@@ -74,6 +89,10 @@ class ExternalSourceConfiguration extends DataFlow::Configuration {
74
89
}
75
90
}
76
91
92
+ /**
93
+ * A dataflow configuration tracking the flow of the Android APK MIME type to
94
+ * the `setType` or `setTypeAndNormalize` method of an intent.
95
+ */
77
96
private class PackageArchiveMimeTypeConfiguration extends TaintTracking2:: Configuration {
78
97
PackageArchiveMimeTypeConfiguration ( ) { this = "PackageArchiveMimeTypeConfiguration" }
79
98
@@ -105,6 +124,6 @@ private class PackageArchiveMimeTypeConfiguration extends TaintTracking2::Config
105
124
}
106
125
}
107
126
108
- from DataFlow:: PathNode source , DataFlow:: PathNode sink , ExternalSourceConfiguration config
127
+ from DataFlow:: PathNode source , DataFlow:: PathNode sink , APKConfiguration config
109
128
where config .hasFlowPath ( source , sink )
110
129
select sink .getNode ( ) , source , sink , "Arbitrary Android APK installation."
0 commit comments