Skip to content

Commit 3405db3

Browse files
committed
Add qhelp
1 parent 6152c8a commit 3405db3

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class IntentUriPermissionManipulation extends Activity {
2+
3+
// BAD: the user-provided Intent is returned as-is
4+
public void dangerous() {
5+
Intent intent = getIntent();
6+
intent.putExtra("result", "resultData");
7+
setResult(intent);
8+
}
9+
10+
// GOOD: a new Intent is created and returned
11+
public void safe() {
12+
Intent intent = new Intent();
13+
intent.putExtra("result", "resultData");
14+
setResult(intent);
15+
}
16+
17+
// GOOD: the user-provided Intent is sanitized before being returned
18+
public void sanitized() {
19+
Intent intent = getIntent();
20+
intent.putExtra("result", "resultData");
21+
intent.removeFlags(
22+
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
23+
setResult(intent);
24+
}
25+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>When an Android component expects a result from an Activity, <code>startActivityForResult</code> can be used.
7+
The started Activity can then use <code>setResult</code> to return the appropriate data to the calling component.</p>
8+
<p>If an Activity obtains the incoming, user-provided Intent and directly returns it via <code>setResult</code>
9+
without any checks, the application may be unintentionally giving arbitrary access to its Content Providers, even
10+
if they are not exported, as long as they are configured with the attribute <code>android:grantUriPermissions="true"</code>.
11+
This happens because the attacker adds the appropriate URI permission flags to the provided Intent, which take effect
12+
once the Intent is reflected back.</p>
13+
</overview>
14+
15+
<recommendation>
16+
<p>Avoid returning user-provided or untrusted Intents via <code>setResult</code>. Use a new Intent instead.</p>
17+
<p>If it is required to use the received Intent, make sure that it does not contain URI permission flags, either
18+
by checking them with <code>Intent.getFlags</code> or removing them with <code>Intent.removeFlags</code>.</p>
19+
</recommendation>
20+
21+
<example>
22+
<p>The following sample contains three examples. In the first example, a user-provided Intent is obtained and
23+
directly returned back with <code>setResult</code>, which is dangerous. In the second example, a new Intent
24+
is created to safely return the desired data. The third example shows how the obtained Intent can be sanitized
25+
by removing dangerous flags before using it to return data to the calling component.
26+
</p>
27+
28+
<sample src="IntentUriPermissionManipulation.java" />
29+
</example>
30+
31+
<references>
32+
<li>Google Help: <a href="https://support.google.com/faqs/answer/9267555?hl=en">Remediation for Intent Redirection Vulnerability</a>.</li>
33+
</references>
34+
</qhelp>

0 commit comments

Comments
 (0)