Security Playbook
21 · APIs & mobile5 min read

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

Where does your mobile app keep the refresh token?
Stored in

Convenient but plain text on disk.

Unencrypted device backup copied by malware on a PC
✕ Exposed
Other app on a rooted / jailbroken phone
✕ Exposed
Anyone who downloads your app and decompiles it
✓ Protected
Keep tokens in the Keychain (iOS) or Keystore-backed EncryptedSharedPreferences (Android). Never ship API secrets inside the app: anything in the binary is public, so call your own backend instead.
Pick a storage location and see which common threats can read the token.

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