2
2
3
3
import java
4
4
import 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
7
6
private import semmle.code.java.security.ArbitraryApkInstallation
8
7
9
8
/**
10
9
* A dataflow configuration for flow from an external source of an APK to the
11
10
* `setData[AndType][AndNormalize]` method of an intent.
12
11
*/
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 }
15
14
16
- override predicate isSource ( DataFlow:: Node node ) { node instanceof ExternalApkSource }
17
-
18
- override predicate isSink ( DataFlow:: Node node ) {
15
+ predicate isSink ( DataFlow:: Node node ) {
19
16
exists ( MethodAccess ma |
20
17
ma .getMethod ( ) instanceof SetDataMethod and
21
18
ma .getArgument ( 0 ) = node .asExpr ( ) and
22
19
(
23
- any ( PackageArchiveMimeTypeConfiguration c ) . hasFlowToExpr ( ma .getQualifier ( ) )
20
+ PackageArchiveMimeTypeConfiguration:: hasFlowToExpr ( ma .getQualifier ( ) )
24
21
or
25
- any ( InstallPackageActionConfiguration c ) . hasFlowToExpr ( ma .getQualifier ( ) )
22
+ InstallPackageActionConfiguration:: hasFlowToExpr ( ma .getQualifier ( ) )
26
23
)
27
24
)
28
25
}
29
26
}
30
27
28
+ module ApkConfiguration = DataFlow:: Make< ApkConf > ;
29
+
31
30
/**
32
31
* A dataflow configuration tracking the flow from the `android.content.Intent.ACTION_INSTALL_PACKAGE`
33
32
* constant to either the constructor of an intent or the `setAction` method of an intent.
34
33
*
35
34
* This is used to track if an intent is used to install an APK.
36
35
*/
37
- private class InstallPackageActionConfiguration extends TaintTracking3 :: Configuration {
38
- InstallPackageActionConfiguration ( ) { this = "InstallPackageActionConfiguration" }
36
+ private module InstallPackageActionConfig implements DataFlow :: StateConfigSig {
37
+ class FlowState = string ;
39
38
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
42
41
}
43
42
44
- override predicate isAdditionalTaintStep (
43
+ predicate isAdditionalFlowStep (
45
44
DataFlow:: Node node1 , DataFlow:: FlowState state1 , DataFlow:: Node node2 ,
46
45
DataFlow:: FlowState state2
47
46
) {
@@ -63,24 +62,30 @@ private class InstallPackageActionConfiguration extends TaintTracking3::Configur
63
62
)
64
63
}
65
64
66
- override predicate isSink ( DataFlow:: Node node , DataFlow:: FlowState state ) {
65
+ predicate isSink ( DataFlow:: Node node , DataFlow:: FlowState state ) {
67
66
state = "hasPackageInstallAction" and node .asExpr ( ) .getType ( ) instanceof TypeIntent
68
67
}
68
+
69
+ predicate isBarrier ( DataFlow:: Node node , FlowState state ) { none ( ) }
69
70
}
70
71
72
+ private module InstallPackageActionConfiguration =
73
+ TaintTracking:: MakeWithState< InstallPackageActionConfig > ;
74
+
71
75
/**
72
76
* A dataflow configuration tracking the flow of the Android APK MIME type to
73
77
* the `setType` or `setTypeAndNormalize` method of an intent, followed by a call
74
78
* to `setData[AndType][AndNormalize]`.
75
79
*/
76
- private class PackageArchiveMimeTypeConfiguration extends TaintTracking2 :: Configuration {
77
- PackageArchiveMimeTypeConfiguration ( ) { this = "PackageArchiveMimeTypeConfiguration" }
80
+ private module PackageArchiveMimeTypeConfig implements DataFlow :: StateConfigSig {
81
+ class FlowState = string ;
78
82
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
81
86
}
82
87
83
- override predicate isAdditionalTaintStep (
88
+ predicate isAdditionalFlowStep (
84
89
DataFlow:: Node node1 , DataFlow:: FlowState state1 , DataFlow:: Node node2 ,
85
90
DataFlow:: FlowState state2
86
91
) {
@@ -98,8 +103,13 @@ private class PackageArchiveMimeTypeConfiguration extends TaintTracking2::Config
98
103
)
99
104
}
100
105
101
- override predicate isSink ( DataFlow:: Node node , DataFlow:: FlowState state ) {
106
+ predicate isSink ( DataFlow:: Node node , DataFlow:: FlowState state ) {
102
107
state = "typeSet" and
103
108
node instanceof SetDataSink
104
109
}
110
+
111
+ predicate isBarrier ( DataFlow:: Node node , FlowState state ) { none ( ) }
105
112
}
113
+
114
+ private module PackageArchiveMimeTypeConfiguration =
115
+ TaintTracking:: MakeWithState< PackageArchiveMimeTypeConfig > ;
0 commit comments