@@ -14,6 +14,7 @@ import java
1414import semmle.code.java.frameworks.android.Intent
1515import semmle.code.java.dataflow.DataFlow
1616import semmle.code.java.dataflow.TaintTracking2
17+ import semmle.code.java.dataflow.TaintTracking3
1718private import semmle.code.java.dataflow.ExternalFlow
1819import DataFlow:: PathGraph
1920
@@ -22,6 +23,17 @@ class PackageArchiveMimeTypeLiteral extends StringLiteral {
2223 PackageArchiveMimeTypeLiteral ( ) { this .getValue ( ) = "application/vnd.android.package-archive" }
2324}
2425
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+
2537/** A method that sets the MIME type of an intent. */
2638class SetTypeMethod extends Method {
2739 SetTypeMethod ( ) {
@@ -48,7 +60,12 @@ class SetDataMethod extends Method {
4860
4961/** A dataflow sink for the URI of an intent. */
5062class 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+ }
5269}
5370
5471/** A method that generates a URI. */
@@ -84,14 +101,44 @@ class ApkConfiguration extends DataFlow::Configuration {
84101 exists ( MethodAccess ma |
85102 ma .getMethod ( ) instanceof SetDataMethod and
86103 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+ )
88109 )
89110 }
90111}
91112
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+
92138/**
93139 * 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]`.
95142 */
96143private class PackageArchiveMimeTypeConfiguration extends TaintTracking2:: Configuration {
97144 PackageArchiveMimeTypeConfiguration ( ) { this = "PackageArchiveMimeTypeConfiguration" }
0 commit comments