Android and iOS Security Models
A phone is a computer that its owner carries everywhere, full of other people's code. Its operating system therefore assumes that apps are not trusted: each one runs in a sandbox, sees only its own files, gets sensitive data only through permissions the user grants, and must be signed. Most mobile app vulnerabilities are not breaks of that model but apps that undermine it from inside: exporting components to every other app, storing tokens where backups pick them up, turning off the platform's TLS checks. To review an app you need to know what the platform already guarantees. This lesson compares the two platforms' models and audits the course's sample app's permissions.
The shared design
| Layer | Android | iOS / iPadOS |
|---|---|---|
| Boot integrity | Verified Boot (dm-verity), rollback protection; the device warns when the bootloader is unlocked | secure boot chain from the Boot ROM; only Apple-signed system code runs |
| App identity and signing | every APK/AAB is signed by the developer; signature schemes v2 (Android 7), v3 with key rotation (Android 9), v4; updates must carry the same signing identity (signing) | every app is signed with an Apple-issued certificate; the kernel refuses unsigned code (code signing) |
| Sandbox | a Linux user ID per app plus SELinux policies (enforcing since Android 5); private directory under /data/data/<package> |
a container directory per app and a sandbox profile; entitlements grant extra capabilities |
| Permissions | install-time ("normal", "signature") and runtime ("dangerous", since Android 6); one-time and auto-reset permissions in newer versions | runtime prompts for each protected resource; the app must state the reason in Info.plist (NS…UsageDescription) |
| Inter-app communication | intents to activities, services, receivers; content providers; exported components are reachable by other apps | URL schemes, universal links, app extensions, the pasteboard; more restricted by design |
| Key storage | Android Keystore, hardware-backed in the TEE, or StrongBox secure elements (Android 9+); keys can require user authentication | Keychain, protected by the Secure Enclave; Data Protection classes tie file keys to the passcode |
| Network defaults | cleartext HTTP blocked by default for apps targeting Android 9+; Network Security Configuration | App Transport Security (ATS) requires HTTPS with TLS 1.2+ by default |
| Device and app attestation | Play Integrity API, key attestation | App Attest, DeviceCheck |
| Distribution | Google Play review; sideloading possible (an explicit user setting) | App Store review; enterprise and limited alternative distribution |
The two converge on the same ideas; they differ in openness. Android lets users install apps from anywhere and lets apps talk to each other more freely, which puts more weight on each app's own configuration (Android manifest review). iOS restricts more by default, so reviews focus on what apps relax (Info.plist review).
Secure hardware, briefly
Both platforms keep their most valuable keys in hardware the main processor can't read: Android's TEE (Trusted Execution Environment, a separate secure world on the same chip) or StrongBox secure element, and Apple's Secure Enclave, a separate processor since the A7 chip (2013). Keys generated there never leave in plain form. An app asks the hardware to sign or decrypt, optionally only after a fingerprint or face check. This is the right home for an app's long-term secrets, and the code-flaws lesson shows what happens when apps use files instead.
Permissions: ask for what you use
Each permission is a promise to the user and a liability for the developer: whatever an app can access, a bug or a malicious SDK inside it can leak. The LabHome Android app's manifest asks for nine permissions. The audit compares them with the app's real features:
# Permissions the LabHome Android app requests (synthetic manifest) vs. the features it really has
LEVEL = { # protection level of each Android permission (simplified)
"android.permission.INTERNET": "normal", "android.permission.BLUETOOTH_SCAN": "dangerous",
"android.permission.BLUETOOTH_CONNECT": "dangerous", "android.permission.CAMERA": "dangerous",
"android.permission.ACCESS_FINE_LOCATION": "dangerous", "android.permission.READ_CONTACTS": "dangerous",
"android.permission.RECORD_AUDIO": "dangerous", "android.permission.SYSTEM_ALERT_WINDOW": "special",
"android.permission.POST_NOTIFICATIONS": "dangerous",
}
requested = list(LEVEL) # the app asks for all of them
NEEDED_BY = {
"android.permission.INTERNET": "cloud API", "android.permission.BLUETOOTH_SCAN": "find the plug (neverForLocation)",
"android.permission.BLUETOOTH_CONNECT": "pair with the plug", "android.permission.CAMERA": "scan the pairing QR code",
"android.permission.POST_NOTIFICATIONS": "alerts",
}
for perm in requested:
short = perm.rsplit(".", 1)[1]
use = NEEDED_BY.get(perm)
verdict = f"needed: {use}" if use else "NOT NEEDED: remove"
if perm == "android.permission.ACCESS_FINE_LOCATION":
verdict += " (Android 12+ scans BLE without location when BLUETOOTH_SCAN has neverForLocation)"
print(f"{short:22} {LEVEL[perm]:9} {verdict}")
dangerous_extra = [p for p in requested if p not in NEEDED_BY and LEVEL[p] != "normal"]
print(f"{len(dangerous_extra)} sensitive permissions without a feature: each is data the app could leak or abuse")INTERNET normal needed: cloud API
BLUETOOTH_SCAN dangerous needed: find the plug (neverForLocation)
BLUETOOTH_CONNECT dangerous needed: pair with the plug
CAMERA dangerous needed: scan the pairing QR code
ACCESS_FINE_LOCATION dangerous NOT NEEDED: remove (Android 12+ scans BLE without location when BLUETOOTH_SCAN has neverForLocation)
READ_CONTACTS dangerous NOT NEEDED: remove
RECORD_AUDIO dangerous NOT NEEDED: remove
SYSTEM_ALERT_WINDOW special NOT NEEDED: remove
POST_NOTIFICATIONS dangerous needed: alerts
4 sensitive permissions without a feature: each is data the app could leak or abuse
Four of nine are unnecessary. Location is a common case: older Android versions required location permission to scan for BLE devices (because BLE scans can locate a user), but since Android 12 the BLUETOOTH_SCAN permission with the neverForLocation flag allows scanning without it. Contacts and microphone access were probably copied from a template or pulled in by an SDK. On iOS the same review applies to the NS…UsageDescription keys in Info.plist and to the entitlements file.
What the model does not protect
- Data the app itself exposes: exported components, world-readable files, logs, backups, the clipboard.
- Data on a compromised device: on a rooted or jailbroken device, or with malware holding accessibility permissions, the sandbox is bypassed. Apps handling high-value data check device integrity (Play Integrity, App Attest) and keep secrets in hardware, but can't fully defend there.
- The network, when apps disable certificate validation or allow cleartext.
- The server: anything the app can do, an attacker with the API and a stolen token can do too. Authorisation must be enforced on the backend (OAuth and OIDC).
How weaknesses in this area are detected
- Manifest and Info.plist review (next lessons): permissions, exported components, network settings, entitlements.
- SDK inventory: which third-party libraries come with which permissions and data flows.
- Platform reports: Play Console pre-launch reports and App Store privacy details (the developer's own declarations, which must be true).
- Device-integrity signals in server logs for apps that use attestation.
How it is fixed
- Least privilege: remove unneeded permissions, use scoped alternatives (photo picker,
neverForLocation, one-time permissions), request at the moment of use with an explanation. - Keep secrets in Keystore/Keychain, hardware-backed, with user authentication for sensitive keys.
- Don't weaken platform defaults (cleartext, TLS validation, exported components).
- Enforce on the server everything that matters; treat the app as untrusted input.
Pitfalls
- Assuming the sandbox protects data the app puts in shared storage, logs or backups.
- Requesting permissions "in case a future feature needs them".
- Treating a rooted-device check as a security boundary: it raises the cost, it doesn't make the device trustworthy.
Practice
1. Which two platform features stop one app from reading another app's private files?
The per-app sandbox (a separate Linux UID plus SELinux on Android; a per-app container and sandbox profile on iOS). An app can still expose its files deliberately or by mistake, for example through an exported content provider.
2. Why does Android require every update of an app to be signed with the same key (or a rotated one)?
Signing identity is the app's identity: it decides whether the update may replace the installed app and access its data. A different key would let anyone ship an "update" that takes over an app's private data.
3. The LabHome app removes ACCESS_FINE_LOCATION. What must it add so that BLE scanning still works on Android 12+?
Declare BLUETOOTH_SCAN with android:usesPermissionFlags="neverForLocation" (and request it at runtime), promising not to derive location from scans. Older Android versions still need location for scanning, so it may be kept with android:maxSdkVersion="30".
Test yourself
How does Android isolate apps from each other?
- By encrypting each APK
- A separate Linux user ID per app plus SELinux policies
- By running each app in a virtual machine
- It doesn't
Where should an app keep a long-term private key?
- In SharedPreferences
- In the Android Keystore / iOS Keychain, hardware-backed
- In a file on external storage
- In the app's source code
How many of the sample app's nine permissions were unnecessary?
- None
- Two
- Four
- Nine
What does the platform security model NOT protect?
- Other apps' private files
- Data the app itself exposes through logs, backups or exported components
- Unsigned system code
- The boot chain