Secure Storage and Secrets in Mobile Apps
What may live on the device and how.
Hello. In this lesson I will take you through 3 ideas, one at a time.
Why it matters: What may live on the device and how. After each idea I will ask you one quick question.
In this lessonFollows you as you read
Assume the device is hostile
The short version: A phone can be lost, rooted or inspected.
A phone can be lost, rooted or inspected. Anything shipped in the app can be read. So store as little as possible, and nothing that would hurt if extracted.
Session tokens belong in the platform's secure storage, not in plain preferences. Server keys do not belong in the app at all.
Where should a server API key be stored?
Tokens and sessions
The short version: Use short-lived access tokens with a refresh flow.
Use short-lived access tokens with a refresh flow. Let users see and end their sessions. Require a fresh login or device biometrics before sensitive actions such as changing payout details.
On sign out, clear tokens and cached personal data.
What should happen before changing payout details?
Data at rest and in logs
The short version: Encrypt sensitive cached data and keep it short.
Encrypt sensitive cached data and keep it short. Never write personal data, tokens or full requests to logs or crash reports. Review what third-party analytics collect.
Screens showing sensitive data should be hidden from the app switcher preview where the platform allows.
- Ship no secret you cannot afford to lose
- Tokens go in secure storage and expire quickly
- Step-up checks protect sensitive actions
- Logs and crash reports must hold no personal data
List everything your app stores on the device. For each item decide: remove, move to secure storage, or encrypt and shorten.
Mark it complete to track your progress on this device.