1- < p > In Android applications, broadcasting intents is security-sensitive. For example, it has led in the past to the following vulnerability:</ p >
2- < ul >
3- < li > < a href ="https://www.cve.org/CVERecord?id=CVE-2018-9489 "> CVE-2018-9489</ a > </ li >
4- </ ul >
5- < p > By default, broadcasted intents are visible to every application, exposing all sensitive information they contain.</ p >
6- < p > This rule raises an issue when an intent is broadcasted without specifying any "receiver permission".</ p >
7- < h2 > Ask Yourself Whether</ h2 >
8- < ul >
9- < li > The intent contains sensitive information.</ li >
10- < li > Intent reception is not restricted.</ li >
11- </ ul >
12- < p > There is a risk if you answered yes to any of those questions.</ p >
13- < h2 > Recommended Secure Coding Practices</ h2 >
14- < p > Restrict the access to broadcasted intents. See < a
15- href ="https://developer.android.com/guide/components/broadcasts.html#restricting_broadcasts_with_permissions "> Android documentation</ a > for more
16- information.</ p >
17- < h2 > Sensitive Code Example</ h2 >
18- < pre >
1+ < p > Broadcasted intents in Android are visible to every application by default, which can expose sensitive information.</ p >
2+ < h2 > Why is this an issue?</ h2 >
3+ < p > By default, broadcasted intents are visible to every application on the device, exposing all sensitive information that intents contain. This rule
4+ raises an issue when an intent is broadcasted without specifying a receiver permission.</ p >
5+ < p > Methods like < code > sendBroadcast</ code > , < code > sendBroadcastAsUser</ code > , < code > sendOrderedBroadcast</ code > , and
6+ < code > sendOrderedBroadcastAsUser</ code > that are called without a receiver permission parameter or with < code > null</ code > for the permission allow any
7+ application to receive the broadcast.</ p >
8+ < h3 > What is the potential impact?</ h3 >
9+ < h4 > Information disclosure</ h4 >
10+ < p > If an intent contains sensitive data such as user credentials, personal information, or internal application state, any malicious application
11+ installed on the same device can intercept and read this data.</ p >
12+ < h4 > Privilege escalation</ h4 >
13+ < p > A malicious application could listen for broadcasted intents to trigger unauthorized actions or manipulate application behavior, potentially
14+ gaining access to functionality that should be restricted.</ p >
15+ < h2 > How to fix it</ h2 >
16+ < h3 > Code examples</ h3 >
17+ < p > The following code broadcasts an intent without specifying a receiver permission, making it accessible to all applications on the device.</ p >
18+ < h4 > Noncompliant code example</ h4 >
19+ < pre data-diff-id ="1 " data-diff-type ="noncompliant ">
1920import android.content.BroadcastReceiver
2021import android.content.Context
2122import android.content.Intent
@@ -33,20 +34,20 @@ <h2>Sensitive Code Example</h2>
3334 initialData: String,
3435 initialExtras: Bundle,
3536 broadcastPermission: String) {
36- context.sendBroadcast(intent) // Sensitive
37- context.sendBroadcastAsUser(intent, user) // Sensitive
37+ context.sendBroadcast(intent) // Noncompliant
38+ context.sendBroadcastAsUser(intent, user) // Noncompliant
3839
3940 // Broadcasting intent with "null" for receiverPermission
40- context.sendBroadcast(intent, null) // Sensitive
41- context.sendBroadcastAsUser(intent, user, null) // Sensitive
42- context.sendOrderedBroadcast(intent, null) // Sensitive
41+ context.sendBroadcast(intent, null) // Noncompliant
42+ context.sendBroadcastAsUser(intent, user, null) // Noncompliant
43+ context.sendOrderedBroadcast(intent, null) // Noncompliant
4344 context.sendOrderedBroadcastAsUser(intent, user, null, resultReceiver,
44- scheduler, initialCode, initialData, initialExtras) // Sensitive
45+ scheduler, initialCode, initialData, initialExtras) // Noncompliant
4546 }
4647}
4748</ pre >
48- < h2 > Compliant Solution </ h2 >
49- < pre >
49+ < h4 > Compliant solution </ h4 >
50+ < pre data-diff-id =" 1 " data-diff-type =" compliant " >
5051import android.content.BroadcastReceiver
5152import android.content.Context
5253import android.content.Intent
@@ -68,12 +69,18 @@ <h2>Compliant Solution</h2>
6869 context.sendBroadcast(intent, broadcastPermission)
6970 context.sendBroadcastAsUser(intent, user, broadcastPermission)
7071 context.sendOrderedBroadcast(intent, broadcastPermission)
71- context.sendOrderedBroadcastAsUser(intent, user,broadcastPermission, resultReceiver,
72+ context.sendOrderedBroadcastAsUser(intent, user, broadcastPermission, resultReceiver,
7273 scheduler, initialCode, initialData, initialExtras)
7374 }
7475}
7576</ pre >
76- < h2 > See</ h2 >
77+ < h2 > Resources</ h2 >
78+ < h3 > Documentation</ h3 >
79+ < ul >
80+ < li > < a href ="https://developer.android.com/guide/components/broadcasts.html#restricting_broadcasts_with_permissions "> Android documentation</ a > -
81+ Broadcast Overview - Security considerations and best practices</ li >
82+ </ ul >
83+ < h3 > Standards</ h3 >
7784< ul >
7885 < li > OWASP - < a href ="https://owasp.org/Top10/A04_2021-Insecure_Design/ "> Top 10 2021 Category A4 - Insecure Design</ a > </ li >
7986 < li > OWASP - < a href ="https://mas.owasp.org/checklists/MASVS-PLATFORM/ "> Mobile AppSec Verification Standard - Platform Interaction
@@ -85,7 +92,5 @@ <h2>See</h2>
8592 < li > OWASP - < a href ="https://owasp.org/www-project-mobile-top-10/2023-risks/m8-security-misconfiguration "> Mobile Top 10 2024 Category M8 - Security
8693 Misconfiguration</ a > </ li >
8794 < li > CWE - < a href ="https://cwe.mitre.org/data/definitions/927 "> CWE-927 - Use of Implicit Intent for Sensitive Communication</ a > </ li >
88- < li > < a href ="https://developer.android.com/guide/components/broadcasts.html#restricting_broadcasts_with_permissions "> Android documentation</ a > -
89- Broadcast Overview - Security considerations and best practices</ li >
9095</ ul >
9196
0 commit comments