Skip to content

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; NSURLIsExcludedFromBackupKey on iOS caches you wouldn't want imaged.
  • Tokens, keys, and PII into Keystore/Keychain — never SharedPreferences/NSUserDefaults.
  • FLAG_SECURE on screens displaying sensitive data; blur on applicationDidEnterBackground for iOS.
  • No secrets in log statements, ever — grep for Log. and print(/NSLog in release builds.
  • Data Protection classes on files that matter: NSFileProtectionComplete for 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/ClipboardManager after first use.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.