@@ -14,6 +14,7 @@ import java
14
14
import semmle.code.java.frameworks.android.Intent
15
15
import semmle.code.java.dataflow.DataFlow
16
16
import semmle.code.java.dataflow.TaintTracking2
17
+ import semmle.code.java.dataflow.TaintTracking3
17
18
private import semmle.code.java.dataflow.ExternalFlow
18
19
import DataFlow:: PathGraph
19
20
@@ -22,6 +23,17 @@ class PackageArchiveMimeTypeLiteral extends StringLiteral {
22
23
PackageArchiveMimeTypeLiteral ( ) { this .getValue ( ) = "application/vnd.android.package-archive" }
23
24
}
24
25
26
+ class InstallPackageAction extends Expr {
27
+ InstallPackageAction ( ) {
28
+ this .( StringLiteral ) .getValue ( ) = "android.intent.action.INSTALL_PACKAGE"
29
+ or
30
+ exists ( VarAccess va |
31
+ va .getVariable ( ) .hasName ( "ACTION_INSTALL_PACKAGE" ) and
32
+ va .getQualifier ( ) .getType ( ) instanceof TypeIntent
33
+ )
34
+ }
35
+ }
36
+
25
37
/** A method that sets the MIME type of an intent. */
26
38
class SetTypeMethod extends Method {
27
39
SetTypeMethod ( ) {
@@ -48,7 +60,12 @@ class SetDataMethod extends Method {
48
60
49
61
/** A dataflow sink for the URI of an intent. */
50
62
class SetDataSink extends DataFlow:: ExprNode {
51
- SetDataSink ( ) { this .getExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof SetDataMethod }
63
+ SetDataSink ( ) {
64
+ exists ( MethodAccess ma |
65
+ this .getExpr ( ) = ma .getQualifier ( ) and
66
+ ma .getMethod ( ) instanceof SetDataMethod
67
+ )
68
+ }
52
69
}
53
70
54
71
/** A method that generates a URI. */
@@ -84,14 +101,44 @@ class ApkConfiguration extends DataFlow::Configuration {
84
101
exists ( MethodAccess ma |
85
102
ma .getMethod ( ) instanceof SetDataMethod and
86
103
ma .getArgument ( 0 ) = node .asExpr ( ) and
87
- any ( PackageArchiveMimeTypeConfiguration c ) .hasFlowToExpr ( ma )
104
+ (
105
+ any ( PackageArchiveMimeTypeConfiguration c ) .hasFlowToExpr ( ma .getQualifier ( ) )
106
+ or
107
+ any ( InstallPackageActionConfiguration c ) .hasFlowToExpr ( ma .getQualifier ( ) )
108
+ )
88
109
)
89
110
}
90
111
}
91
112
113
+ private class InstallPackageActionConfiguration extends TaintTracking3:: Configuration {
114
+ InstallPackageActionConfiguration ( ) { this = "InstallPackageActionConfiguration" }
115
+
116
+ override predicate isSource ( DataFlow:: Node source ) {
117
+ source .asExpr ( ) instanceof InstallPackageAction
118
+ }
119
+
120
+ override predicate isAdditionalTaintStep (
121
+ DataFlow:: Node node1 , DataFlow:: FlowState state1 , DataFlow:: Node node2 ,
122
+ DataFlow:: FlowState state2
123
+ ) {
124
+ state1 instanceof DataFlow:: FlowStateEmpty and
125
+ state2 = "hasPackageInstallAction" and
126
+ exists ( ConstructorCall cc |
127
+ cc .getConstructedType ( ) instanceof TypeIntent and
128
+ node1 .asExpr ( ) = cc .getArgument ( 0 ) and
129
+ node2 .asExpr ( ) = cc
130
+ )
131
+ }
132
+
133
+ override predicate isSink ( DataFlow:: Node node , DataFlow:: FlowState state ) {
134
+ state = "hasPackageInstallAction" and node .asExpr ( ) .getType ( ) instanceof TypeIntent
135
+ }
136
+ }
137
+
92
138
/**
93
139
* A dataflow configuration tracking the flow of the Android APK MIME type to
94
- * the `setType` or `setTypeAndNormalize` method of an intent.
140
+ * the `setType` or `setTypeAndNormalize` method of an intent, followed by a call
141
+ * to `setData[AndType][AndNormalize]`.
95
142
*/
96
143
private class PackageArchiveMimeTypeConfiguration extends TaintTracking2:: Configuration {
97
144
PackageArchiveMimeTypeConfiguration ( ) { this = "PackageArchiveMimeTypeConfiguration" }
0 commit comments