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

    1. iOS: store credentials in the Keychain (kSecAttrAccessibleWhenUnlockedThisDeviceOnly, or AfterFirstUnlockThisDeviceOnly for background work).
    2. Android: use EncryptedSharedPreferences (androidx.security) or DataStore with a Tink AEAD backed by the Android Keystore.
    3. Flutter: use flutter_secure_storage (Keychain / Keystore).
    4. 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 app

    References

    Related checks (M9)