What are the main security risks of exported components, intents and WebViews on Android?
AndroidSenior
In shortExported components accept input from any app, so they must be minimal and validate everything; internal communication uses explicit intents and immutable PendingIntents; WebViews must not load untrusted URLs with JavaScript bridges enabled.
Model answer
- Exported components: since API 31
android:exportedmust be explicit. Export only real entry points (launcher, App Links, share targets); protect internal IPC withsignature-level permissions. - Validate input: every extra, URI and action from an exported component is attacker-controlled. Check types, ranges, schemes and hosts. Never forward a received
Intent(or one taken from its extras) tostartActivity: that’s intent redirection, which lets other apps reach your unexported components. - PendingIntents: use
FLAG_IMMUTABLEand explicit intents, so whoever holds the PendingIntent can’t change its target or data. - Providers:
ContentProviders andFileProviderpaths must not allow path traversal or expose more than intended; grant URI permissions narrowly. - WebViews: JavaScript off unless needed; no
addJavascriptInterfacefor untrusted origins (use origin-restrictedaddWebMessageListener); allowlist navigation;allowFileAccess = false; open third-party pages in Custom Tabs. - Network: release builds trust only system CAs (Network Security Config), with pinning for high-value APIs.
- Server side: the device can be compromised; Play Integrity verdicts with a nonce and server-side checks decide trust for sensitive operations.
What they're looking for
Knowledge of exported (explicit since API 31), intent validation and intent redirection, PendingIntent mutability, ContentProvider and FileProvider path issues, WebView hardening, and server-side trust with Play Integrity.
Common mistakes
- Exporting activities "just in case".
- Forwarding a received Intent extra to startActivity.
- Using addJavascriptInterface on pages loaded from intent extras.
More android questions
- How do you make sure background work in a mobile app stops when the user leaves the screen?Mid-level
- What's the difference between a configuration change and process death on Android, and what survives each?Mid-level
- How would you modularize a large Android app, and how do you keep builds fast?Senior
- How do you store an auth token securely on Android?Mid-level