MOB-STORAGEintermediate · 6 min · upd. 2026-10
Insecure Storage
One of the most common and easy-to-find flaw classes in mobile apps is storing sensitive data —tokens, passwords, keys, PII, session information— on the device unencrypted or in accessible locations. Since the device can be rooted/jailbroken (or backed up), anything the app writes in the clear is exposed. It’s the MASVS-STORAGE category of the OWASP standard and almost always produces findings.
flowchart TD
APP["App"] --> SP["SharedPreferences / NSUserDefaults"]
APP --> DB["SQLite / Realm"]
APP --> FS["Files / cache"]
APP --> SEC["Keystore / Keychain"]
SP --> LEAK["Leak if cleartext"]
DB --> LEAK
FS --> LEAK
SEC --> OK["OK if protection class is right"]
LEAK --> BK["Backups / another app / root"]
Threat model
Section titled “Threat model”The attacker who exploits insecure storage has some degree of access to the device or its copies:
- Root/jailbreak: reads any file in the app’s container.
- Backup: extracts data from
adb backup(Android) or an iTunes/iCloud backup (iOS). - Another app: reads external storage or poorly permissioned directories.
- Physical access: lost/stolen device without effective disk encryption.
What they want: session tokens and JWTs, passwords, API keys, PINs, encryption keys, and PII. The classic mistake is encrypting data but storing the key next to it.
Where each platform stores
Section titled “Where each platform stores”Android
Section titled “Android”/data/data/<package>/ shared_prefs/*.xml # SharedPreferences (key-value, often cleartext) databases/*.db # SQLite (app data) files/ # internal files cache/ # cache# external storage (historically: readable by other apps with permission)/sdcard/Android/data/<package>/# the right place for secrets:# Android Keystore -> hardware-backed keys (TEE/StrongBox)/var/mobile/Containers/Data/Application/<UUID>/ Library/Preferences/*.plist # NSUserDefaults (key-value, cleartext) Documents/ Library/ tmp/ # files, SQLite, cache# the right place for secrets:# Keychain -> system encrypted store, with protection classesAccessing the data (Android)
Section titled “Accessing the data (Android)”# with root or run-as (if the app is debuggable)adb shell run-as com.target.app cat /data/data/com.target.app/shared_prefs/prefs.xmladb shell "su -c 'ls -la /data/data/com.target.app/'"# databasesadb pull /data/data/com.target.app/databases/app.dbsqlite3 app.db ".tables"# backup without root (if allowBackup=true)adb backup -f backup.ab -noapk com.target.app # extract with abe.jarAccessing the data (iOS)
Section titled “Accessing the data (iOS)”# with jailbreak, SSH to the device, or Objectionobjection -g com.target.app exploreios keychain dump # dump the app's Keychainios nsuserdefaults get # NSUserDefaults (cleartext keys)env # app container pathsWhat to look for
Section titled “What to look for”# in the app container, any format (prefs, SQLite, files, cache, logs)grep -rniE 'token|password|secret|api[_-]?key|BEGIN|jwt|bearer' /data/data/com.target.app/- Session tokens / JWTs (see JWT), passwords, API keys, PINs.
- Encryption keys stored next to the encrypted data (classic mistake).
- PII, card data, messages, histories.
Less obvious leaks
Section titled “Less obvious leaks”# logs: the app writes sensitive data to logcat / NSLogadb logcat | grep -i target- Keyboard cache and pasteboard (iOS), background screenshots (snapshot on minimise).
- WebView cache, uncleared in-memory data.
- Cloud backups (iCloud / Google Backup) that include sensitive data.
- Logging/crash libraries (Crashlytics, Sentry) that capture sensitive parameters.
Red Team
Section titled “Red Team”Testing against an app you own or have permission to test:
- Map the container and dump
shared_prefs/.plist, SQLite, and files; grep for cleartext secrets. - Dump the Keystore/Keychain and check whether secrets are where they belong, with the right protection class.
- Test the backup:
adb backupand, on iOS, an unencrypted backup with extraction tools. - Watch logs and pasteboard while using sensitive features (login, payment).
- Check the crypto: if there’s encrypted data, look for the key in the same container or derive it with Frida by hooking the encryption.
Blue Team
Section titled “Blue Team”- Secrets in the secure store: Android Keystore / iOS Keychain (with the right protection class), never in SharedPreferences/NSUserDefaults/cleartext files.
- Minimise: don’t store what you don’t need; short-lived, renewable tokens.
- Correct encryption: don’t store the key next to the data; use non-extractable keys (hardware-backed). On Android,
EncryptedSharedPreferences/SQLCipher; derive keys with the Keystore. - allowBackup=false (Android) or exclude sensitive data from the backup; Data Protection (iOS,
WhenUnlocked). - Don’t log sensitive data; clear cache/pasteboard; protect the background capture (blank screen when backgrounding).
Checklist
Section titled “Checklist”- Locate the app’s data directories (Android/iOS)
- Cleartext SharedPreferences / NSUserDefaults
- SQLite/Realm databases with sensitive data
- Files, cache, and external storage
- Keystore/Keychain: are they used? right protection class?
- Encryption keys stored next to the data
- Leaks in logs, pasteboard, background screenshots, crash reports
- Extractable backup (allowBackup / unencrypted backup)