Skip to content

Commit 25336df

Browse files
authored
Merge pull request #8873 from atorralba/atorralba/android-startactivity-flowstep
Java: Add flow step from startActivity to getIntent
2 parents 43b425d + cf55f18 commit 25336df

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
Added a data flow step for tainted Android intents that are sent to other activities and accessed there via `getIntent()`.

java/ql/lib/semmle/code/java/frameworks/android/Intent.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,25 @@ class GrantWriteUriPermissionFlag extends GrantUriPermissionFlag {
176176
GrantWriteUriPermissionFlag() { this.hasName("FLAG_GRANT_WRITE_URI_PERMISSION") }
177177
}
178178

179+
/**
180+
* A value-preserving step from the Intent argument of a `startActivity` call to
181+
* a `getIntent` call in the Activity the Intent pointed to in its constructor.
182+
*/
183+
private class StartActivityIntentStep extends AdditionalValueStep {
184+
override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
185+
exists(MethodAccess startActivity, MethodAccess getIntent, ClassInstanceExpr newIntent |
186+
startActivity.getMethod().overrides*(any(ContextStartActivityMethod m)) and
187+
getIntent.getMethod().overrides*(any(AndroidGetIntentMethod m)) and
188+
newIntent.getConstructedType() instanceof TypeIntent and
189+
DataFlow::localExprFlow(newIntent, startActivity.getArgument(0)) and
190+
newIntent.getArgument(1).getType().(ParameterizedType).getATypeArgument() =
191+
getIntent.getReceiverType() and
192+
n1.asExpr() = startActivity.getArgument(0) and
193+
n2.asExpr() = getIntent
194+
)
195+
}
196+
}
197+
179198
private class IntentBundleFlowSteps extends SummaryModelCsv {
180199
override predicate row(string row) {
181200
row =
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:versionCode="1"
5+
android:versionName="1.0"
6+
package="com.example.app">
7+
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:label="@string/app_name"
13+
android:supportsRtl="true"
14+
android:theme="@style/AppTheme">
15+
16+
<activity
17+
android:name=".TestStartActivityToGetIntent.SomeActivity"
18+
android:exported="false">
19+
</activity>
20+
21+
</application>
22+
</manifest>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import android.app.Activity;
2+
import android.content.Context;
3+
import android.content.Intent;
4+
5+
public class TestStartActivityToGetIntent {
6+
7+
static Object source() {
8+
return null;
9+
}
10+
11+
static void sink(Object sink) {}
12+
13+
public void test(Context ctx) {
14+
Intent intent = new Intent(null, SomeActivity.class);
15+
intent.putExtra("data", (String) source());
16+
ctx.startActivity(intent);
17+
}
18+
19+
static class SomeActivity extends Activity {
20+
21+
public void test() {
22+
sink(getIntent().getStringExtra("data")); // $ hasValueFlow
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)