Mobile apps: secure storage and secrets in the binary
A mobile app runs on a device you don't control and ships as a file anyone can decompile. Where to keep tokens on the device, why API keys inside the app are public, and the basics of trusting a mobile client.
In one sentence
Keep user tokens in the Keychain / Keystore, never ship real secrets in the app (the binary is public), and treat every request from the app as untrusted input.
Where the token lives decides who can take it
Convenient but plain text on disk.
Rules for mobile clients
- Tokens in the Keychain (iOS) or Keystore-backed storage (Android), with "this device only" flags so they don't travel in backups.
- No third-party secrets in the app. A payments or AI API key in the bundle will be extracted. Call your backend, which holds the key and enforces limits.
- Don't trust the client: prices, roles, feature flags and "isPremium" must be checked server-side; modified apps send whatever they want.
- Validate TLS normally and consider certificate pinning only if you can operate it (pin rotations break apps that can't update).
- Deep links are input: validate every parameter that arrives through a custom URL scheme or universal link.
Key takeaways
- 01Store tokens in the Keychain / Keystore, not in preferences or files.
- 02Anything in the app binary is public: keep secrets on your backend.
- 03Treat mobile requests as untrusted and authorize on the server.
- 04Validate deep-link parameters like any other input.
Check your understanding
1 of 3
Where should a mobile app store user tokens?
Related concepts
Secrets management
A secret in a repo is leaked, even after you delete it. Keep secrets in a vault or the platform's secret store, scan before push, scope every key, and revoke first, investigate second.
6 min read →JWT
A JWT is base64, not encryption: anyone can read it. Its signature only proves the server issued it, and only if you verify it with a fixed algorithm and check the expiry.
8 min read →Sessions & cookies
A session cookie is as good as a password while it's valid. Ship it as HttpOnly; Secure; SameSite=Lax, keep it short-lived, and rotate it on login and privilege changes.
7 min read →