|
3 | 3 |
|
4 | 4 | <overview>
|
5 | 5 | <p>
|
6 |
| -Fragments are reusable parts of an Android application's user interface. |
7 |
| -Even though a Fragment controls its own lifecycle and layout and handles its input events, |
8 |
| -it cannot exist on its own: it must be hosted either by an Activity or another fragment. |
9 |
| -This means that a Fragment will be accessible by third-party applications (that is, exported) |
10 |
| -only if its hosting Activity is itself exported. |
| 6 | +When fragments are instantiated with externally provided names, this exposes any exported activity that dynamically |
| 7 | +creates and hosts the fragment to fragment injection. A malicious application could provide the |
| 8 | +name of an arbitrary fragment, even one not designed to be externally accessible, and inject it into the activity. |
| 9 | +Thus, effectively bypassing access controls and exposing the application to unintended effects. |
11 | 10 | </p>
|
12 | 11 | <p>
|
13 |
| -If an exported Activity dinamically creates and hosts Fragments instantiated with externally |
14 |
| -provided names, a malicious application could provide the name of an arbitrary Fragment, even |
15 |
| -one not designed to be externally accessible, and inject it into the Activity, effectively |
16 |
| -bypassing access controls and exposing the application to unintended effects. |
| 12 | +Fragments are reusable parts of an Android application's user interface. |
| 13 | +Even though a fragment controls its own lifecycle and layout, and handles its input events, |
| 14 | +it cannot exist on its own: it must be hosted either by an activity or another fragment. |
| 15 | +This means that, normally, a fragment will be accessible by third-party applications (that is, exported) |
| 16 | +only if its hosting activity is itself exported. |
17 | 17 | </p>
|
18 | 18 | </overview>
|
19 | 19 |
|
20 | 20 | <recommendation>
|
21 | 21 | <p>
|
22 |
| -In general, do not instantiate classes (including Fragments) with user-provided names |
23 |
| -without proper validation. |
| 22 | +In general, do not instantiate classes (including fragments) with user-provided names |
| 23 | +unless the name has been properly validated. |
24 | 24 |
|
25 |
| -Also, if an exported Activity is extending the <code>PreferenceActivity</code> class, make sure that |
| 25 | +Also, if an exported activity is extending the <code>PreferenceActivity</code> class, make sure that |
26 | 26 | the <code>isValidFragment</code> method is overriden and only returns <code>true</code> when the provided
|
27 |
| -<code>fragmentName</code> points to an intended Fragment. |
| 27 | +<code>fragmentName</code> points to an intended fragment. |
28 | 28 | </p>
|
29 | 29 | </recommendation>
|
30 | 30 |
|
31 | 31 | <example>
|
32 | 32 | <p>
|
33 | 33 | The following example shows two cases: in the first one, untrusted data is used to instantiate and
|
34 |
| -add a Fragment to an Activity, while in the second one, a Fragment is safely added with a static name. |
| 34 | +add a fragment to an activity, while in the second one, a fragment is safely added with a static name. |
35 | 35 | </p>
|
36 | 36 | <sample src="FragmentInjection.java" />
|
37 | 37 |
|
38 | 38 | <p>
|
39 |
| -The next example shows two Activities extending <code>PreferenceActivity</code>. The first one overrides |
40 |
| -<code>isValidFragment</code>, but it wrongly returns <code>true</code> inconditionally. The second Activity |
41 |
| -correctly overrides <code>isValidFragment</code> to only return <code>true</code> when <code>fragmentName</code> |
42 |
| -is a trusted Fragment name. |
| 39 | +The next example shows two activities that extend <code>PreferenceActivity</code>. The first activity overrides |
| 40 | +<code>isValidFragment</code>, but it wrongly returns <code>true</code> unconditionally. The second activity |
| 41 | +correctly overrides <code>isValidFragment</code> so that it only returns <code>true</code> when <code>fragmentName</code> |
| 42 | +is a trusted fragment name. |
43 | 43 | </p>
|
44 | 44 | <sample src="FragmentInjectionInPreferenceActivity.java" />
|
45 | 45 | </example>
|
|
0 commit comments