22
33import  java
44import  semmle.code.java.dataflow.DataFlow
5- import  semmle.code.java.dataflow.TaintTracking2
6- import  semmle.code.java.dataflow.TaintTracking3
5+ import  semmle.code.java.dataflow.TaintTracking
76private  import  semmle.code.java.security.ArbitraryApkInstallation
87
98/** 
109 * A dataflow configuration for flow from an external source of an APK to the 
1110 * `setData[AndType][AndNormalize]` method of an intent. 
1211 */ 
13- class   ApkConfiguration   extends   DataFlow:: Configuration  { 
14-   ApkConfiguration ( )  {  this   =   "ApkConfiguration"  } 
12+ private   module  ApkConf  implements   DataFlow:: ConfigSig  { 
13+   predicate   isSource ( DataFlow :: Node   node )  {  node   instanceof   ExternalApkSource  } 
1514
16-   override  predicate  isSource ( DataFlow:: Node  node )  {  node  instanceof  ExternalApkSource  } 
17- 
18-   override  predicate  isSink ( DataFlow:: Node  node )  { 
15+   predicate  isSink ( DataFlow:: Node  node )  { 
1916    exists ( MethodAccess  ma  | 
2017      ma .getMethod ( )  instanceof  SetDataMethod  and 
2118      ma .getArgument ( 0 )  =  node .asExpr ( )  and 
2219      ( 
23-         any ( PackageArchiveMimeTypeConfiguration   c ) . hasFlowToExpr ( ma .getQualifier ( ) ) 
20+         PackageArchiveMimeTypeConfiguration:: hasFlowToExpr ( ma .getQualifier ( ) ) 
2421        or 
25-         any ( InstallPackageActionConfiguration   c ) . hasFlowToExpr ( ma .getQualifier ( ) ) 
22+         InstallPackageActionConfiguration:: hasFlowToExpr ( ma .getQualifier ( ) ) 
2623      ) 
2724    ) 
2825  } 
2926} 
3027
28+ module  ApkConfiguration =  DataFlow:: Make< ApkConf > ;
29+ 
3130/** 
3231 * A dataflow configuration tracking the flow from the `android.content.Intent.ACTION_INSTALL_PACKAGE` 
3332 * constant to either the constructor of an intent or the `setAction` method of an intent. 
3433 * 
3534 * This is used to track if an intent is used to install an APK. 
3635 */ 
37- private  class   InstallPackageActionConfiguration   extends  TaintTracking3 :: Configuration  { 
38-   InstallPackageActionConfiguration ( )   {   this   =   "InstallPackageActionConfiguration"   } 
36+ private  module  InstallPackageActionConfig  implements  DataFlow :: StateConfigSig  { 
37+   class   FlowState   =   string ; 
3938
40-   override   predicate  isSource ( DataFlow:: Node  source )  { 
41-     source .asExpr ( )  instanceof  InstallPackageAction 
39+   predicate  isSource ( DataFlow:: Node  source ,   FlowState   state )  { 
40+     source .asExpr ( )  instanceof  InstallPackageAction   and   state   instanceof  DataFlow :: FlowStateEmpty 
4241  } 
4342
44-   override   predicate  isAdditionalTaintStep ( 
43+   predicate  isAdditionalFlowStep ( 
4544    DataFlow:: Node  node1 ,  DataFlow:: FlowState  state1 ,  DataFlow:: Node  node2 , 
4645    DataFlow:: FlowState  state2 
4746  )  { 
@@ -63,24 +62,30 @@ private class InstallPackageActionConfiguration extends TaintTracking3::Configur
6362    ) 
6463  } 
6564
66-   override   predicate  isSink ( DataFlow:: Node  node ,  DataFlow:: FlowState  state )  { 
65+   predicate  isSink ( DataFlow:: Node  node ,  DataFlow:: FlowState  state )  { 
6766    state  =  "hasPackageInstallAction"  and  node .asExpr ( ) .getType ( )  instanceof  TypeIntent 
6867  } 
68+ 
69+   predicate  isBarrier ( DataFlow:: Node  node ,  FlowState  state )  {  none ( )  } 
6970} 
7071
72+ private  module  InstallPackageActionConfiguration = 
73+   TaintTracking:: MakeWithState< InstallPackageActionConfig > ;
74+ 
7175/** 
7276 * A dataflow configuration tracking the flow of the Android APK MIME type to 
7377 * the `setType` or `setTypeAndNormalize` method of an intent, followed by a call 
7478 * to `setData[AndType][AndNormalize]`. 
7579 */ 
76- private  class   PackageArchiveMimeTypeConfiguration   extends  TaintTracking2 :: Configuration  { 
77-   PackageArchiveMimeTypeConfiguration ( )   {   this   =   "PackageArchiveMimeTypeConfiguration"   } 
80+ private  module  PackageArchiveMimeTypeConfig  implements  DataFlow :: StateConfigSig  { 
81+   class   FlowState   =   string ; 
7882
79-   override  predicate  isSource ( DataFlow:: Node  node )  { 
80-     node .asExpr ( )  instanceof  PackageArchiveMimeTypeLiteral 
83+   predicate  isSource ( DataFlow:: Node  node ,  FlowState  state )  { 
84+     node .asExpr ( )  instanceof  PackageArchiveMimeTypeLiteral  and 
85+     state  instanceof  DataFlow:: FlowStateEmpty 
8186  } 
8287
83-   override   predicate  isAdditionalTaintStep ( 
88+   predicate  isAdditionalFlowStep ( 
8489    DataFlow:: Node  node1 ,  DataFlow:: FlowState  state1 ,  DataFlow:: Node  node2 , 
8590    DataFlow:: FlowState  state2 
8691  )  { 
@@ -98,8 +103,13 @@ private class PackageArchiveMimeTypeConfiguration extends TaintTracking2::Config
98103    ) 
99104  } 
100105
101-   override   predicate  isSink ( DataFlow:: Node  node ,  DataFlow:: FlowState  state )  { 
106+   predicate  isSink ( DataFlow:: Node  node ,  DataFlow:: FlowState  state )  { 
102107    state  =  "typeSet"  and 
103108    node  instanceof  SetDataSink 
104109  } 
110+ 
111+   predicate  isBarrier ( DataFlow:: Node  node ,  FlowState  state )  {  none ( )  } 
105112} 
113+ 
114+ private  module  PackageArchiveMimeTypeConfiguration = 
115+   TaintTracking:: MakeWithState< PackageArchiveMimeTypeConfig > ;
0 commit comments