high · M9 · MASVS-STORAGE-1 · PTKD-DYN-STORAGE-SECRET
Secret written to device storage
A credential was found in a file the app wrote (shared-prefs / database / cache), readable on a rooted or backed-up device.
How it is exploited
A secret (token, key, password) was written to app storage in plaintext during the run. Backups, run-as on debuggable builds, and any local-file bug turn that file into a credential dump.
Why it matters
Persisted credentials outlive the session and leak through every local-storage channel.
How to fix it
- Store secrets in Keystore-backed EncryptedSharedPreferences (Android) or the Keychain (iOS).
- Delete the plaintext copies on upgrade and shorten token lifetimes so leaked ones age out.
Android: EncryptedSharedPreferences
val prefs = EncryptedSharedPreferences.create(context, "secure",
MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build(),
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM)Does your app have this?
PTKD checks your build or your source project for PTKD-DYN-STORAGE-SECRET and every other check in this knowledge base.
Scan your appReferences
Related checks (M9)
- Android file or preferences created world-readable or world-writable
- Public Supabase bucket can be listed by anyone
- Public Supabase storage bucket (heuristic)
- Sensitive data written to external storage
- Sensitive data written to the log
- Tokens or passwords stored in plain app preferences
- Keychain item accessible while locked
- Tokens or passwords written to the device log