The Token That Survived Logout
#ios-security — buyer logged in as original owner after iPhone sale
Security: User sold iPhone after factory reset. Buyer restored from iCloud backup — still logged in with payment methods and order history.
The trap: Auth token stored in UserDefaults — unencrypted, always in iCloud backups, survives device restore.
Your task
Fix `SecureAuthManager` in `SecureStorage.swift`: Keychain with .whenUnlockedThisDeviceOnly, check Keychain on login state, verify deletion on logout.
Book: UserDefaults for settings · Prod: UserDefaults token survives restore to new owner.
Skills you'll prove
Interview Tip
When asked about iOS data storage or security, say: "The rule is simple: UserDefaults for preferences, Keychain for secrets. UserDefaults is an unencrypted plist file that is always included in iCloud backups. If you store an auth token there, it survives factory resets when the new owner restores from a backup. I fixed a security incident where exactly this happened — a user sold their iPhone, the buyer restored from iCloud, and our app UserDefaults token kept them logged in as the original owner with full access to payment methods. The fix was moving to Keychain with kSecAttrAccessibleWhenUnlockedThisDeviceOnly. The ThisDeviceOnly suffix is critical — it tells iOS to strip these items during device restore. Without it, even Keychain items survive."