A broadcast receiver is registered without saying whether other apps may send to it

tx0/kotlin:receiver-without-export-flagrecommendedwarningsecurity/authn-authzdepth fastsecurity, android, cwe-925

What it finds

Since Android 14, an app targeting it has to pass RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED when it registers a receiver for broadcasts that are not system broadcasts, and gets a SecurityException otherwise. Without the flag on older versions the receiver is exported, so any app can send it intents.

From the rule's source, receiver_without_export_flag.rs.

Example from the rule's tests
fun listen(context: Context, receiver: BroadcastReceiver, filter: IntentFilter) {    context.registerReceiver(receiver, filter)tx0 reports: the receiver is registered without RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED    context.registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED)    ContextCompat.registerReceiver(context, receiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED)    LocalBroadcastManager.getInstance(context).registerReceiver(receiver, filter)}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:receiver-without-export-flag" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/kotlin:receiver-without-export-flag] reason="..."

tx0 explain tx0/kotlin:receiver-without-export-flag shows the same in the terminal. Found a false positive? Report it.