Lesson 4 of 13 · 13m
Where Data Actually Lands
SharedPreferences and NSUserDefaults are plaintext XML/plist, backups ship private dirs off-device, logcat and switcher snapshots leak the screen — the sandbox only stops other apps on a stock phone.
Where the bytes actually go
SharedPreferences writes an XML file at /data/data/<pkg>/shared_prefs/<name>.xml — plaintext, mode 0600, owned by your UID. NSUserDefaults writes a plist at Library/Preferences/<bundleid>.plist — plaintext, same idea. SQLite databases are plaintext unless you linked SQLCipher. Files land in files/, caches in cache/. The sandbox protects these paths from other apps on an unrooted phone. It protects them from nothing else.
Nothing else turns out to be a long list.
Backups. android:allowBackup defaults to true. Auto Backup ships up to 25 MB of your private directory to the user's Google Drive; adb backup (deprecated but still functional) extracts it to a laptop over USB. Forensic examiners have pulled session tokens out of app backups for years — the fix is allowBackup="false" or an explicit backup_rules.xml/full_backup_content.xml exclude for the sensitive paths. On iOS, Finder/iTunes backups include the app container unless a file carries NSURLIsExcludedFromBackupKey; an unencrypted backup is plaintext on the examiner's disk. Files marked NSFileProtectionComplete are locked to the passcode and survive as ciphertext — but only if you set the class.
Logs. Log.d(TAG, "token=" + token) writes to the kernel log buffer. Since API 16 other apps can't read logcat — but adb logcat on any paired machine reads everything, debug builds ship, and pentest reports still list token-in-logcat findings every year. On iOS, NSLog/unified logging streams into Console and idevicesyslog on the host it trusts. R8 does not strip log calls. Gate them on BuildConfig.DEBUG or write a release stub.
The screen itself. Android caches the task-snapshot image for the app switcher; FLAG_SECURE on the window suppresses it — and also blocks screenshots and the screen being shown to assistants. iOS takes a snapshot on applicationDidEnterBackground for the same reason and keeps it on flash; the standard pentest check is backgrounding the app and harvesting Snapshot/ images. The fix is a blur or logo overlay before resigning active.
The clipboard. Android below API 31 let any foreground app read ClipboardManager silently; API 31+ (Android 12) pops a toast naming the reader. iOS let any foreground app read UIPasteboard.general until the iOS 14 banner exposed it — TikTok was caught in June 2020 reading the pasteboard on every keystroke interval, and the banner is the reason anyone noticed. iOS 16 went further: non-user-initiated paste requires consent. Copying a password into the clipboard is broadcasting it.
The keyboard. secureTextEntry/inputType="textPassword" disable the keyboard's autocorrect cache; without it, iOS stores typed strings — including the sensitive ones — in its adaptive cache. Third-party keyboards granted "Full Access" get network egress. Users install them; your threat model includes them.
The filesystem itself. Full-device encryption is the floor — modern iPhones encrypt everything with SEP-bound keys and Android uses FBE (file-based encryption) with per-key classes, which is why DirectBoot and deviceProtectedStorage exist for pre-unlock data. The distinction that matters: FBE protects a powered-off stolen phone. It does nothing once the device is unlocked, which is the state forensic tools and most attackers meet it in.
The wrong model
"Internal storage is safe because it's private" conflates two different adversaries. Against other apps on a stock phone: yes, UID separation holds. Against a stolen-and-imaged device, a forensic backup, an ADB session, a jailbroken install, or the user themselves: it's a directory of plaintext files with 0600 permissions on a filesystem someone else owns the root password to. Defense isn't the directory. Defense is what you put in it.
Practice
allowBackup="false"(or exclude rules) on any app holding session material;NSURLIsExcludedFromBackupKeyon iOS caches you wouldn't want imaged.- Tokens, keys, and PII into Keystore/Keychain — never
SharedPreferences/NSUserDefaults. FLAG_SECUREon screens displaying sensitive data; blur onapplicationDidEnterBackgroundfor iOS.- No secrets in log statements, ever — grep for
Log.andprint(/NSLogin release builds. - Data Protection classes on files that matter:
NSFileProtectionCompletefor anything you wouldn't want read from an off-device backup. - Don't put secrets through the clipboard. If the user copies a password, clear
UIPasteboard/ClipboardManagerafter first use.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
They Got Root on a Fully Patched Ivanti VPN and the Integrity Checker Said Everything Was Fine
Volexity caught an attacker chaining zero-days into unauthenticated root on an Ivanti Connect Secure appliance running the latest build. The payload never touched disk, commands rode in over the same HTTPS requests as the exploit, and Ivanti's Integrity Checker reported no modifications.
Gitea Shipped 21 CVEs in One Release and Eleven of Them Are the Same Bug
Gitea 28.3.0 landed November 1 with twenty-one CVE fixes. Read the list and a pattern jumps out: more than half are the same failure repeated across different route handlers, where a token scoped to public data gets handed private data anyway. That's not twenty-one mistakes.
php2shell: The PHP Bug That Fires Before Your Code Runs
Two critical PHP flaws landed October 21 and were in CISA's exploited-vulnerabilities catalog five days later. The 9.2 score isn't the part that should bother you. It's where the bug lives — it goes off while PHP is still assembling $_POST, before a single line of your application has run.
A Certificate Authority's Private Keys Were the Numbers 4, 56 and 66
Eight eMudhra intermediate CA keys turned out to be recoverable from their own public certificates. Not stolen — computable, because the key generation produced almost no entropy. A researcher pulled all eight in under a second and signed a message with each one to prove it.