medium · M9 · MASVS-STORAGE-1 · PTKD-STORAGE-RN-TOKEN-PLAIN
Login tokens or passwords kept in unencrypted app storage
The app saves login tokens (or a password or PIN) with AsyncStorage or localStorage. Both are plain, unencrypted files inside the app: on a rooted or jailbroken phone, from an unencrypted backup, or through code running in a WebView, the token can be copied and used to sign in as the user without their password.
How it is exploited
lib/supabase.ts from the starter creates the client with `auth: { storage: AsyncStorage, persistSession: true }`, and the login screen also runs `AsyncStorage.setItem('password', password)` for a 'remember me' switch. On Android, AsyncStorage is a SQLite file in the app folder: an unencrypted adb backup, a rooted phone or a malicious app with root copies it, and the refresh token signs in as the user for weeks. The saved password works on other sites too.
Why it matters
Account takeover from a lost, rooted or backed-up phone; with a stored password, takeover on every service where the user reused it.
How to fix it
- Never store the password: use the refresh token, or biometric unlock with the token in the Keychain.
- Move tokens to expo-secure-store / react-native-keychain (Capacitor: a secure-storage plugin).
- For the Supabase session use LargeSecureStore (Supabase React Native docs): the session stays in AsyncStorage but encrypted, with the key in SecureStore.
- Set android:allowBackup="false" (Expo: android.allowBackup: false) so app files are not copied into backups.
Does your app have this?
PTKD checks your build or your source project for PTKD-STORAGE-RN-TOKEN-PLAIN 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
- Tokens or passwords stored in plain app preferences
- Keychain item accessible while locked