medium · M9 · MASVS-STORAGE-1 · PTKD-FLUTTER-PREFS-SECRET
Tokens or passwords stored in plain app preferences
The app writes a value whose key or variable name says it is a credential (access token, refresh token, password, API key, session) to plain preferences: SharedPreferences (Flutter, Android), UserDefaults / @AppStorage (iOS) or Jetpack DataStore preferences. These are unencrypted files: they are included in device backups and can be read on a rooted or jailbroken phone.
How it is exploited
After login the app stores the access token with prefs.setString('access_token', token) (Flutter), UserDefaults.standard.set(token, forKey: "authToken") (iOS) or getSharedPreferences(...).edit().putString("token", token) (Android). Each is a plain file: FlutterSharedPreferences.xml, the app's preferences plist, shared_prefs/*.xml. A device backup, a rooted or jailbroken phone or malware with root reads it and replays the token until it expires.
Why it matters
Session takeover from a lost, rooted or backed-up phone; refresh tokens keep it working for weeks.
How to fix it
- iOS: store credentials in the Keychain (kSecAttrAccessibleWhenUnlockedThisDeviceOnly, or AfterFirstUnlockThisDeviceOnly for background work).
- Android: use EncryptedSharedPreferences (androidx.security) or DataStore with a Tink AEAD backed by the Android Keystore.
- Flutter: use flutter_secure_storage (Keychain / Keystore).
- On the next launch, move any value still in the plain store to the secure one and delete it from the plain store.
Does your app have this?
PTKD checks your build or your source project for PTKD-FLUTTER-PREFS-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
- Secret written to device storage
- Keychain item accessible while locked
- Tokens or passwords written to the device log