88import java
99import semmle.code.java.frameworks.android.Intent
1010import semmle.code.java.dataflow.DataFlow
11- import semmle.code.java.dataflow.TaintTracking
11+ import semmle.code.java.dataflow.TaintTracking2
1212private import semmle.code.java.dataflow.ExternalFlow
1313
1414class PackageArchiveMimeTypeLiteral extends StringLiteral {
@@ -18,57 +18,57 @@ class PackageArchiveMimeTypeLiteral extends StringLiteral {
1818class SetTypeMethod extends Method {
1919 SetTypeMethod ( ) {
2020 this .hasName ( [ "setType" , "setTypeAndNormalize" ] ) and
21- this .getDeclaringType ( ) . getASupertype * ( ) instanceof TypeIntent
21+ this .getDeclaringType ( ) instanceof TypeIntent
2222 }
2323}
2424
2525class SetDataAndTypeMethod extends Method {
2626 SetDataAndTypeMethod ( ) {
2727 this .hasName ( [ "setDataAndType" , "setDataAndTypeAndNormalize" ] ) and
28- this .getDeclaringType ( ) . getASupertype * ( ) instanceof TypeIntent
28+ this .getDeclaringType ( ) instanceof TypeIntent
2929 }
3030}
3131
3232class SetDataMethod extends Method {
3333 SetDataMethod ( ) {
3434 this .hasName ( [ "setData" , "setDataAndNormalize" , "setDataAndType" , "setDataAndTypeAndNormalize" ] ) and
35- this .getDeclaringType ( ) . getASupertype * ( ) instanceof TypeIntent
35+ this .getDeclaringType ( ) instanceof TypeIntent
3636 }
3737}
3838
3939class SetDataSink extends DataFlow:: ExprNode {
4040 SetDataSink ( ) { this .getExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof SetDataMethod }
41-
42- DataFlow:: ExprNode getUri ( ) { result .asExpr ( ) = this .getExpr ( ) .( MethodAccess ) .getArgument ( 0 ) }
4341}
4442
45- class UriParseMethod extends Method {
46- UriParseMethod ( ) {
47- this .hasName ( [ "parse" , "fromFile" ] ) and
48- this .getDeclaringType ( ) .hasQualifiedName ( "android.net" , "Uri" )
43+ class UriConstructorMethod extends Method {
44+ UriConstructorMethod ( ) {
45+ this .hasQualifiedName ( "android.net" , "Uri" , [ "parse" , "fromFile" , "fromParts" ] )
4946 }
5047}
5148
5249class ExternalSource extends DataFlow:: Node {
5350 ExternalSource ( ) {
5451 sourceNode ( this , "android-external-storage-dir" ) or
55- this .asExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof UriParseMethod or
52+ this .asExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof UriConstructorMethod or
5653 this .asExpr ( ) .( StringLiteral ) .getValue ( ) .matches ( [ "file://%" , "http://%" , "https://%" ] )
5754 }
5855}
5956
60- class ExternalSourceConfiguration extends DataFlow2 :: Configuration {
57+ class ExternalSourceConfiguration extends DataFlow :: Configuration {
6158 ExternalSourceConfiguration ( ) { this = "ExternalSourceConfiguration" }
6259
6360 override predicate isSource ( DataFlow:: Node node ) { node instanceof ExternalSource }
6461
6562 override predicate isSink ( DataFlow:: Node node ) {
66- // any(PackageArchiveMimeTypeConfiguration c).hasFlow(_, node)
67- node instanceof SetDataSink
63+ exists ( MethodAccess ma |
64+ ma .getMethod ( ) instanceof SetDataMethod and
65+ ma .getArgument ( 0 ) = node .asExpr ( ) and
66+ any ( PackageArchiveMimeTypeConfiguration c ) .hasFlowToExpr ( ma )
67+ )
6868 }
6969}
7070
71- class PackageArchiveMimeTypeConfiguration extends TaintTracking :: Configuration {
71+ private class PackageArchiveMimeTypeConfiguration extends TaintTracking2 :: Configuration {
7272 PackageArchiveMimeTypeConfiguration ( ) { this = "PackageArchiveMimeTypeConfiguration" }
7373
7474 override predicate isSource ( DataFlow:: Node node ) {
@@ -96,10 +96,9 @@ class PackageArchiveMimeTypeConfiguration extends TaintTracking::Configuration {
9696 override predicate isSink ( DataFlow:: Node node , DataFlow:: FlowState state ) {
9797 state = "typeSet" and
9898 node instanceof SetDataSink
99- // and any(ExternalSourceConfiguration c).hasFlow(_, node.(SetDataSink).getUri())
10099 }
101100}
102101
103- from DataFlow:: PathNode source , DataFlow:: PathNode sink , PackageArchiveMimeTypeConfiguration config
102+ from DataFlow:: PathNode source , DataFlow:: PathNode sink , ExternalSourceConfiguration config
104103where config .hasFlowPath ( source , sink )
105104select sink .getNode ( ) , source , sink , "Android APK installation"
0 commit comments