44 * Android configuration file and sensitive user data.
55 * @kind path-problem
66 * @id java/sensitive-android-file-leak
7+ * @problem.severity warning
78 * @tags security
89 * external/cwe/cwe-200
910 */
1011
1112import java
13+ import semmle.code.java.controlflow.Guards
1214import AndroidFileIntentSink
1315import AndroidFileIntentSource
14- import DataFlow2:: PathGraph
15- import semmle.code.java.dataflow.TaintTracking2
16+ import DataFlow:: PathGraph
1617
17- private class StartsWithSanitizer extends DataFlow2 :: BarrierGuard {
18+ private class StartsWithSanitizer extends DataFlow :: BarrierGuard {
1819 StartsWithSanitizer ( ) { this .( MethodAccess ) .getMethod ( ) .hasName ( "startsWith" ) }
1920
2021 override predicate checks ( Expr e , boolean branch ) {
@@ -27,27 +28,32 @@ private class StartsWithSanitizer extends DataFlow2::BarrierGuard {
2728 }
2829}
2930
30- class AndroidFileLeakConfig extends TaintTracking2 :: Configuration {
31+ class AndroidFileLeakConfig extends TaintTracking :: Configuration {
3132 AndroidFileLeakConfig ( ) { this = "AndroidFileLeakConfig" }
3233
33- /** Holds if it is an access to file intent result. */
34- override predicate isSource ( DataFlow2:: Node src ) {
34+ /**
35+ * Holds if `src` is a read of some Intent-typed method argument guarded by a check like
36+ * `requestCode == REQUEST_CODE__SELECT_CONTENT_FROM_APPS`, where `requestCode` is the first
37+ * argument to `Activity.onActivityResult`.
38+ */
39+ override predicate isSource ( DataFlow:: Node src ) {
3540 exists (
36- AndroidActivityResultInput ai , AndroidFileIntentInput fi , IfStmt ifs , VarAccess intentVar // if (requestCode == REQUEST_CODE__SELECT_CONTENT_FROM_APPS)
41+ AndroidActivityResultInput ai , AndroidFileIntentInput fi , ConditionBlock cb ,
42+ VarAccess intentVar
3743 |
38- ifs .getCondition ( ) . getAChildExpr ( ) .getAChildExpr ( ) .( CompileTimeConstantExpr ) .getIntValue ( ) =
44+ cb .getCondition ( ) .getAChildExpr ( ) .( CompileTimeConstantExpr ) .getIntValue ( ) =
3945 fi .getRequestCode ( ) and
40- ifs .getCondition ( ) . getAChildExpr ( ) .getAChildExpr ( ) = ai .getRequestCodeVar ( ) and
46+ cb .getCondition ( ) .getAChildExpr ( ) = ai .getRequestCodeVar ( ) and
4147 intentVar .getType ( ) instanceof TypeIntent and
42- intentVar . ( Argument ) . getAnEnclosingStmt ( ) = ifs . getThen ( ) and
48+ cb . getBasicBlock ( ) = intentVar . ( Argument ) . getAnEnclosingStmt ( ) and
4349 src .asExpr ( ) = intentVar
4450 )
4551 }
4652
4753 /** Holds if it is a sink of file access in Android. */
48- override predicate isSink ( DataFlow2 :: Node sink ) { sink instanceof AndroidFileSink }
54+ override predicate isSink ( DataFlow :: Node sink ) { sink instanceof AndroidFileSink }
4955
50- override predicate isAdditionalTaintStep ( DataFlow2 :: Node prev , DataFlow2 :: Node succ ) {
56+ override predicate isAdditionalTaintStep ( DataFlow :: Node prev , DataFlow :: Node succ ) {
5157 exists ( MethodAccess aema , AsyncTaskRunInBackgroundMethod arm |
5258 // fileAsyncTask.execute(params) will invoke doInBackground(params) of FileAsyncTask
5359 aema .getQualifier ( ) .getType ( ) = arm .getDeclaringType ( ) and
@@ -60,18 +66,18 @@ class AndroidFileLeakConfig extends TaintTracking2::Configuration {
6066 csma .getMethod ( ) instanceof ContextStartServiceMethod and
6167 ce .getConstructedType ( ) instanceof TypeIntent and // Intent intent = new Intent(context, FileUploader.class);
6268 ce .getArgument ( 1 ) .( TypeLiteral ) .getReferencedType ( ) = ssm .getDeclaringType ( ) and
63- DataFlow2 :: localExprFlow ( ce , csma .getArgument ( 0 ) ) and // context.startService(intent);
69+ DataFlow :: localExprFlow ( ce , csma .getArgument ( 0 ) ) and // context.startService(intent);
6470 prev .asExpr ( ) = csma .getArgument ( 0 ) and
6571 succ .asParameter ( ) = ssm .getParameter ( 0 ) // public int onStartCommand(Intent intent, int flags, int startId) {...} in FileUploader
6672 )
6773 }
6874
69- override predicate isSanitizerGuard ( DataFlow2 :: BarrierGuard guard ) {
75+ override predicate isSanitizerGuard ( DataFlow :: BarrierGuard guard ) {
7076 guard instanceof StartsWithSanitizer
7177 }
7278}
7379
74- from DataFlow2 :: PathNode source , DataFlow2 :: PathNode sink , AndroidFileLeakConfig conf
80+ from DataFlow :: PathNode source , DataFlow :: PathNode sink , AndroidFileLeakConfig conf
7581where conf .hasFlowPath ( source , sink )
7682select sink .getNode ( ) , source , sink , "Leaking arbitrary Android file from $@." , source .getNode ( ) ,
7783 "this user input"
0 commit comments