iOS data storage checks

iOS Keychain & Data Protection security review

iOS sandboxes each app container, yet sensitive tokens and user records still leak through preferences, caches, backups, or overly permissive Keychain items. Accurate reviews tie every observation to a clear threat model.

Where iOS apps accidentally leak sensitive data

Local storage checks fall under MASVS-STORAGE. Even though the iOS sandbox isolates app containers from other apps on an unmodified device, secrets frequently land in locations that survive backups, device transfers, or accidental exposure:

  • UserDefaults / NSUserDefaults: backed by unencrypted property list (.plist) files in Library/Preferences/. Storing OAuth tokens, API keys, or session flags here exposes them in unencrypted backups and container extracts.
  • SQLite, Core Data, and Realm stores: databases under Documents/ or Library/Application Support/ are plaintext unless explicitly encrypted or protected with an appropriate file protection class.
  • URLCache and Cache.db: URLSession can cache HTTP responses containing bearer tokens or personal records on disk unless caching is disabled or controlled via cache policies and headers.
  • App snapshots on backgrounding: iOS captures a screenshot of the active view hierarchy when an app enters the background; account balances, one-time codes, or personal data remain visible unless obscured before backgrounding.
  • Pasteboard and unencrypted plist files: copying secrets to the general UIPasteboard without local-only and expiration options exposes them to other apps or Universal Clipboard, while ad-hoc plist caches often outlive logout.

iOS Keychain accessibility classes

The iOS Keychain is the right store for credentials, refresh tokens, and symmetric keys, provided items use an accessibility constant (kSecAttrAccessible*) matched to when the app actually needs the secret.

Comparing common Keychain accessibility attributes
ConstantRisk profile and intended use
kSecAttrAccessibleWhenUnlockedThisDeviceOnlyPreferred default for foreground credentials and session tokens. Readable only while unlocked and excluded from device-migration backups and iCloud Keychain sync.
kSecAttrAccessibleAfterFirstUnlockThisDeviceOnlyAppropriate when background tasks genuinely need a token after the first unlock following boot, while still preventing off-device backup migration.
Non-ThisDeviceOnly variantsPermit encrypted backup migration or iCloud Keychain sync (when kSecAttrSynchronizable is enabled). Avoid for device-bound session tokens or high-risk credentials.
kSecAttrAccessibleAlways (deprecated)High-risk legacy class allowing access even while locked before first unlock. Replace immediately with a locked-state class.

For secrets that should require explicit user confirmation, attach an access control policy with SecAccessControlCreateWithFlags and .biometryCurrentSet (so newly enrolled biometrics invalidate access) rather than relying on a boolean flag in UserDefaults. Remember also that Keychain items persist across app uninstall and reinstall; clear stale tokens explicitly on first launch when appropriate.

File-level Data Protection and entitlements

Beyond the Keychain, iOS Data Protection encrypts individual files with keys tied to device hardware and the user's passcode. Check both the app's entitlements and per-file attributes:

  • NSFileProtectionComplete: encrypts the file whenever the device is locked; best suited for sensitive cached documents, local databases, and user records accessed only in the foreground.
  • NSFileProtectionCompleteUnlessOpen: allows files created while locked to stay open for writing, then seals them once closed—useful for background logging or downloads that must not expose prior records.
  • com.apple.developer.default-data-protection: verifies the app-wide default protection class in the provisioning profile and embedded entitlements, rather than assuming every file inherits complete protection automatically.
  • Backup exclusion: mark sensitive local files and caches with isExcludedFromBackup (URLResourceValues.isExcludedFromBackup = true) so private artifacts do not leave the device via iCloud or iTunes/Finder backups.

Static IPA signals vs runtime validation

Static analysis of an authorized, unencrypted development or ad-hoc IPA highlights storage candidates before the app ever runs: Mach-O symbols referencing kSecAttrAccessibleAlways, writes to NSUserDefaults, Core Data or SQLite helpers, embedded entitlements such as Keychain sharing groups or com.apple.developer.default-data-protection, and Info.plist settings. FairPlay-encrypted App Store IPAs hide executable code, so static code review requires an unencrypted build.

Confirming actual exposure requires authorized runtime inspection on a test device. Only after exercising login, sensitive workflows, backgrounding, and logout can a validator inspect the app container to see whether plaintext tokens landed in Preferences or Cache.db, whether files carry the intended NSFileProtection* attribute, and whether secrets survive logout. Likewise, if an IPA is re-signed for a public device pool, runtime launch verifies startup behavior but does not validate the original signature or effective entitlements.

Validator reporting structure and remediation guidance

Separate static candidates from confirmed container findings so engineering teams can triage fixes in order of real exposure:

  • Document the exact container path, Keychain service/account identifier, or entitlement key, alongside the observed kSecAttrAccessible* or NSFileProtection* value.
  • Include only a redacted sample of any sensitive value, the build digest, device test state, and whether the artifact remained after logout.
  • State the threat model plainly: plaintext tokens in backups or UserDefaults warrant higher priority than data accessible only with physical unlocked access on a jailbroken device.
  • Recommend migrating secrets to Keychain with ThisDeviceOnly accessibility, setting NSFileProtectionComplete and isExcludedFromBackup on sensitive files, clearing caches and tokens on logout, and masking sensitive screens before background snapshots.

Use the OWASP MASVS checklist to place storage checks inside a broader assessment, and review redacted real-device report structures on the sample reports page.

Related reading