rspec/rules/S5594/xml/rule.adoc

82 lines
3.3 KiB
Plaintext
Raw Normal View History

If an Android component is exported and no permissions are defined then other mobile apps can interact with it and perform potential unauthorized actions.
For instance, an exported content provider can expose sensitive data, if no permissions are defined, to other mobile apps.
It's highly recommended to implement restrictive permissions on exposed components.
2020-06-30 12:50:28 +02:00
== Noncompliant Code Example
2021-02-12 16:35:24 +01:00
In an ``++AndroidManifest.xml++`` file, an exported component is vulnerable when read and write permissions are not defined:
2020-06-30 12:50:28 +02:00
----
<provider
android:authorities="com.example.myapp.MyProvider1"
android:name="com.example.myapp.MyProvider1"
2021-02-11 16:56:46 +01:00
android:exported="true"
android:readPermission="com.example.myapp.READ_PERMISSION" /> <!-- Noncompliant: write permission is not defined -->
2020-06-30 12:50:28 +02:00
<provider
android:authorities="com.example.myapp.MyProvider2"
android:name="com.example.myapp.MyProvider2"
android:exported="true"
2021-02-12 16:35:24 +01:00
android:writePermission="com.example.myapp.WRITE_PERMISSION" /> <!-- Noncompliant: read permission is not defined -->
----
With an ``++<intent-filter>++`` the component's attibute ``++android:exported++`` default value is "true":
----
<activity android:name="com.example.activity1"> <!-- Noncompliant: permissions are not defined -->
<intent-filter>
<action android:name="com.example.OPEN_UI"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
2020-06-30 12:50:28 +02:00
----
2020-06-30 12:50:28 +02:00
== Compliant Solution
2021-02-12 16:35:24 +01:00
In an ``++AndroidManifest.xml++`` file, if it is not needed to export a component to other apps then set the ``++exported++`` property to ``++false++``:
2020-06-30 12:50:28 +02:00
----
<provider
2021-02-11 16:56:46 +01:00
android:authorities="com.example.myapp.MyProvider1"
android:name="com.example.myapp.MyProvider1"
2020-06-30 12:50:28 +02:00
android:exported="false" /> <!-- Compliant -->
----
2021-02-12 16:35:24 +01:00
Otherwise, implement permissions (``++protectionLevel++`` https://developer.android.com/guide/topics/manifest/permission-element#plevel[value] must be defined depending on the sensitivity of the component):
2020-06-30 12:50:28 +02:00
----
2021-02-11 16:56:46 +01:00
<permission android:name="com.example.myapp.A_PERMISSION"
2021-02-12 16:35:24 +01:00
android:description="@string/perm_desc_A_PERMISSION"
android:label="@string/perm_label_A_PERMISSION"
2021-02-11 16:56:46 +01:00
android:protectionLevel="dangerous" />
2020-06-30 12:50:28 +02:00
<provider
2021-02-11 16:56:46 +01:00
android:authorities="com.example.myapp.MyProvider2"
android:name="com.example.myapp.MyProvider2"
2020-06-30 12:50:28 +02:00
android:exported="true"
2021-02-11 16:56:46 +01:00
android:permission="com.example.myapp.A_PERMISSION" /> <!-- Compliant -->
2021-02-12 16:35:24 +01:00
<activity android:name="com.example.activity1"
android:permission="com.example.myapp.A_PERMISSION"> <!-- Compliant -->
<intent-filter>
<action android:name="com.example.OPEN_UI"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
2020-06-30 12:50:28 +02:00
----
== See
* https://mobile-security.gitbook.io/masvs/security-requirements/0x11-v6-interaction_with_the_environment[Mobile AppSec Verification Standard] - Platform Interaction Requirements
* https://www.owasp.org/index.php/Mobile_Top_10_2016-M2-Insecure_Data_Storage[OWASP Mobile Top 10 2016 Category M2] - Insecure Data Storage
* https://cwe.mitre.org/data/definitions/926.html[MITRE, CWE-926] - Improper Export of Android Application Components
* https://www.sans.org/top25-software-errors/#cat3[SANS Top 25] - Porous Defenses
* https://developer.android.com/guide/topics/providers/content-provider-creating#Permissions[developer.android.com] - Implementing content provider permissions