Data Storage Security Interview Questions
SECURITY › Security
Where can an Android app store data, and which locations are private?
What a strong answer covers: Internal storage (filesDir, cacheDir, databases, SharedPreferences, DataStore) is private to the app. External app-specific storage is removed on uninstall and, since scoped storage in Android 10 and 11, isn't readable by other apps. Shared storage (MediaStore, Downloads) is for files the user expects other apps to see. Sensitive data belongs in internal storage, encrypted if needed.
What is the Android Keystore, and why use it?
What a strong answer covers: The Keystore stores cryptographic keys in a container where they can't be extracted from the device, often backed by hardware (TEE or StrongBox). The app asks the Keystore to encrypt, decrypt or sign, but never sees the raw key material. You can require user authentication (biometrics) to use a key. It's the base for encrypting tokens and data.
How would you store an auth token securely?
What a strong answer covers: Encrypt it with an AES key held in the Android Keystore (AES/GCM), and store the ciphertext in DataStore or a file in internal storage. EncryptedSharedPreferences did this but the security-crypto library is deprecated, so many apps use Tink or their own Keystore wrapper. Exclude it from backups and clear it on logout.
What sensitive data leaks happen by accident, and how do you prevent them?
What a strong answer covers: Logging tokens or personal data (strip logs in release with R8 rules or a logging wrapper), backups copying sensitive files (dataExtractionRules and allowBackup), screenshots of sensitive screens in the recents view (FLAG_SECURE), the clipboard, exported components or FileProvider paths exposing files, analytics and crash reports with personal data, and WebView caches.
How would you protect sensitive data in a banking app if the device might be rooted or stolen?
What a strong answer covers: Assume local data can be read on a rooted device: store as little as possible, encrypt with Keystore keys that require user authentication (setUserAuthenticationRequired, biometric with CryptoObject), invalidate keys when biometrics change, keep sessions short and require re-authentication for sensitive actions, use FLAG_SECURE, check Play Integrity on the server, and enable remote session revocation. Root detection is a speed bump, not a guarantee, so server-side checks matter most.