@@ -5,7 +5,9 @@ private import semmle.code.java.frameworks.android.Intent
55//private import semmle.code.java.frameworks.android.AsyncTask
66private import semmle.code.java.frameworks.android.Android
77private import semmle.code.java.dataflow.DataFlow
8+ //private import semmle.code.java.dataflow.DataFlow2
89private import semmle.code.java.dataflow.FlowSteps
10+ //private import semmle.code.java.dataflow.FlowSources
911//private import semmle.code.java.dataflow.ExternalFlow
1012//private import semmle.code.java.dataflow.TaintTracking
1113private import semmle.code.xml.AndroidManifest
@@ -37,31 +39,71 @@ private class DeepLinkIntentStep extends AdditionalValueStep {
3739 ) and
3840 exists ( AndroidComponent andComp |
3941 andComp .getAndroidComponentXmlElement ( ) .( AndroidActivityXmlElement ) .hasDeepLink ( ) and
40- n1 .asExpr ( ) .getFile ( ) = andComp .getFile ( ) // ! ugly, see if better way to do this
42+ n1 .asExpr ( ) .getFile ( ) = andComp .getFile ( ) // ! see if better way to do this
4143 )
4244 }
4345}
4446
45- // ! experimentation with global flow issue - REMOVE
46- /**
47- * A value-preserving step from the Intent variable
48- * the `Intent` Parameter in the `startActivity`.
49- */
50- class IntentVariableToStartActivityStep extends AdditionalValueStep {
51- override predicate step ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
52- exists ( MethodAccess startActivity , Variable intentTypeTest |
47+ // // ! experimentation with global flow issue - REMOVE
48+ // /**
49+ // * A value-preserving step from the Intent variable
50+ // * the `Intent` Parameter in the `startActivity`.
51+ // */
52+ // class IntentVariableToStartActivityStep extends AdditionalValueStep {
53+ // override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
54+ // exists(
55+ // MethodAccess startActivity, Variable intentTypeTest, DataFlow2::Node source,
56+ // DataFlow2::Node sink //ClassInstanceExpr intentTypeTest |
57+ // |
58+ // (
59+ // startActivity.getMethod().overrides*(any(ContextStartActivityMethod m)) or
60+ // startActivity.getMethod().overrides*(any(ActivityStartActivityMethod m))
61+ // ) and
62+ // intentTypeTest.getType() instanceof TypeIntent and // Variable
63+ // //intentTypeTest.getConstructedType() instanceof TypeIntent and // ClassInstanceExpr
64+ // startActivity.getFile().getBaseName() = "MainActivity.java" and // ! REMOVE - for testing only
65+ // //exists(StartComponentConfiguration cfg | cfg.hasFlow(source, sink)) and // GLOBAL FLOW ATTEMPT
66+ // DataFlow::localExprFlow(intentTypeTest.getInitializer(), startActivity.getArgument(0)) and // Variable - gives 5 results - misses the 1st ProfileActivity result since no variable with that one
67+ // //DataFlow::localExprFlow(intentTypeTest, startActivity.getArgument(0)) and // ClassInstanceExpr
68+ // n1.asExpr() = intentTypeTest.getInitializer() and // Variable
69+ // //n1.asExpr() = intentTypeTest and // ClassInstanceExpr
70+ // n2.asExpr() = startActivity.getArgument(0) // ! switch to getStartActivityIntentArg(startActivity)
71+ // )
72+ // }
73+ // }
74+ // ! rename?
75+ // ! below works as intended when run by itself (see latest query in AndroidDeeplinks_RemoteSources.ql),
76+ // ! but not when combined with existing flow steps (non-monotonic recursion)
77+ // ! need to figure out how to combine, or wrap all in global flow?
78+ class StartComponentConfiguration extends DataFlow:: Configuration {
79+ StartComponentConfiguration ( ) { this = "StartComponentConfiguration" }
80+
81+ // Override `isSource` and `isSink`.
82+ override predicate isSource ( DataFlow:: Node source ) {
83+ exists ( ClassInstanceExpr classInstanceExpr |
84+ classInstanceExpr .getConstructedType ( ) instanceof TypeIntent and
85+ source .asExpr ( ) = classInstanceExpr
86+ )
87+ }
88+
89+ override predicate isSink ( DataFlow:: Node sink ) {
90+ exists ( MethodAccess startActivity |
91+ // ! need to handle for all components, not just Activity
5392 (
54- // ! is there a better way to do this?
5593 startActivity .getMethod ( ) .overrides * ( any ( ContextStartActivityMethod m ) ) or
5694 startActivity .getMethod ( ) .overrides * ( any ( ActivityStartActivityMethod m ) )
5795 ) and
58- intentTypeTest .getType ( ) instanceof TypeIntent and
59- //startActivity.getFile().getBaseName() = "MainActivity.java" and // ! REMOVE
60- DataFlow:: localExprFlow ( intentTypeTest .getInitializer ( ) , startActivity .getArgument ( 0 ) ) and
61- n1 .asExpr ( ) = intentTypeTest .getInitializer ( ) and
62- n2 .asExpr ( ) = startActivity .getArgument ( 0 ) // ! switch to getStartActivityIntentArg(startActivity)
96+ sink .asExpr ( ) = startActivity .getArgument ( 0 )
6397 )
6498 }
99+ // Optionally override `isBarrier`.
100+ // Optionally override `isAdditionalFlowStep`.
101+ // Then, to query whether there is flow between some `source` and `sink`,
102+ // write
103+ //
104+ // ```ql
105+ // exists(MyAnalysisConfiguration cfg | cfg.hasFlow(source, sink))
106+ // ```
65107}
66108
67109/* ********************* INTENT METHODS, E.G. parseUri, getData, getExtras, etc. ********************* */
@@ -95,61 +137,8 @@ class AndroidGetDataMethod extends Method {
95137 */
96138class AndroidParseUriMethod extends Method {
97139 AndroidParseUriMethod ( ) {
98- ( this .hasName ( "parseUri" ) or this .hasName ( "getIntent" ) ) and // ! Note to self: getIntent for older versions before deprecation to parseUri
140+ // ! Note to self: getIntent for older versions before deprecation to parseUri
141+ ( this .hasName ( "parseUri" ) or this .hasName ( "getIntent" ) ) and
99142 this .getDeclaringType ( ) instanceof TypeIntent
100143 }
101144}
102- // /**
103- // * A taint step from the Intent argument of a `startActivity` call to
104- // * a `Intent.parseUri` call in the Activity the Intent pointed to in its constructor.
105- // */
106- // private class StartActivityParseUriStep extends AdditionalTaintStep {
107- // override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
108- // exists(MethodAccess startActivity, MethodAccess parseUri, ClassInstanceExpr newIntent |
109- // startActivity.getMethod().overrides*(any(ContextStartActivityMethod m)) and
110- // parseUri.getMethod().overrides*(any(AndroidParseUriMethod m)) and
111- // newIntent.getConstructedType() instanceof TypeIntent and
112- // DataFlow::localExprFlow(newIntent, startActivity.getArgument(0)) and
113- // newIntent.getArgument(1).getType().(ParameterizedType).getATypeArgument() =
114- // parseUri.getReceiverType() and
115- // n1.asExpr() = startActivity.getArgument(0) and
116- // n2.asExpr() = parseUri
117- // )
118- // }
119- // }
120- // /**
121- // * A taint step from the Intent argument of a `startActivity` call to
122- // * a `Intent.get%Extra%` call in the Activity the Intent pointed to in its constructor.
123- // */
124- // private class StartActivityGetDataStep extends AdditionalTaintStep {
125- // override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
126- // exists(MethodAccess startActivity, MethodAccess getData, ClassInstanceExpr newIntent |
127- // startActivity.getMethod().overrides*(any(ContextStartActivityMethod m)) and
128- // getData.getMethod().overrides*(any(AndroidGetDataMethod m)) and
129- // newIntent.getConstructedType() instanceof TypeIntent and
130- // DataFlow::localExprFlow(newIntent, startActivity.getArgument(0)) and
131- // newIntent.getArgument(1).getType().(ParameterizedType).getATypeArgument() =
132- // getData.getReceiverType() and
133- // n1.asExpr() = startActivity.getArgument(0) and
134- // n2.asExpr() = getData
135- // )
136- // }
137- // }
138- // /**
139- // * A taint step from the Intent argument of a `startActivity` call to
140- // * a `Intent.getData` call in the Activity the Intent pointed to in its constructor.
141- // */
142- // private class StartActivityGetExtrasStep extends AdditionalTaintStep {
143- // override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
144- // exists(MethodAccess startActivity, MethodAccess getExtras, ClassInstanceExpr newIntent |
145- // startActivity.getMethod().overrides*(any(ContextStartActivityMethod m)) and
146- // getExtras.getMethod().overrides*(any(AndroidGetExtrasMethod m)) and
147- // newIntent.getConstructedType() instanceof TypeIntent and
148- // DataFlow::localExprFlow(newIntent, startActivity.getArgument(0)) and
149- // newIntent.getArgument(1).getType().(ParameterizedType).getATypeArgument() =
150- // getExtras.getReceiverType() and
151- // n1.asExpr() = startActivity.getArgument(0) and
152- // n2.asExpr() = getExtras
153- // )
154- // }
155- // }
0 commit comments