Join our Newsletter — 33% off our NHI Course
Home› Guides› OWASP Mobile Top 10 M9 Insecure Data Storage…
Guide Application Security

OWASP Mobile Top 10 M9 Insecure Data Storage Guide: Protecting Data at Rest on Devices

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 26 October 2026 14 min read
On this page

Mobile apps routinely leave tokens, personal data and keys on the device in places an attacker, another app or a backup can read. M9 Insecure Data Storage is the ninth risk in the OWASP Mobile Top 10 2024, and OWASP rates it EASY to exploit with SEVERE impact. This guide goes beyond the summary in the OWASP Mobile Top 10 Guide: it sets out what counts as sensitive data, which Android and iOS storage mechanisms protect it and how, the unintentional leak paths (logs, caches, backups, temporary files, cloud storage) that catch most teams, and how to test and evidence the controls. It is written for mobile developers, AppSec engineers and assessors working to MASVS-STORAGE.

Key takeaways

  • Two controls, two failure modes. MASVS splits the problem into MASVS-STORAGE-1 "The app securely stores sensitive data." and MASVS-STORAGE-2 "The app prevents leakage of sensitive data."; most real findings are leaks through logs, caches and backups rather than deliberate storage.
  • Keys belong in hardware-backed stores. Use the Android Keystore and the iOS keychain for key material and tokens, and use them to encrypt anything larger, rather than inventing a storage scheme.
  • Pick the protection class on purpose. iOS defaults third-party app files to Protected Until First User Authentication; data that is not needed while the device is locked should use Complete Protection and keychain items should use a ThisDeviceOnly class.
  • Jetpack Security crypto is deprecated. Google deprecated all security-crypto APIs, including EncryptedSharedPreferences, from version 1.1.0-alpha07 in April 2025 in favour of platform APIs and direct use of the Android Keystore, so new designs should not depend on it.
  • Remote storage is part of M9. OWASP lists cloud storage misconfiguration among M9's manifestations: data the app stores in buckets or Firebase is only as safe as the access rules on that service.

What it is and who it applies to

The official risk name on the OWASP Mobile Top 10 2024 list is M9: Insecure Data Storage, which matches this guide's title. It was M2 in the 2016 list, so the risk has moved down the ranking but not changed in substance. OWASP rates exploitability EASY, prevalence COMMON, detectability AVERAGE and technical and business impact SEVERE. The attack vectors it names are access to the device file system through physical or remote means, weak or absent encryption, malware or malicious apps on the device, and rooted or jailbroken devices that bypass the platform's sandbox.

OWASP's "Am I vulnerable" list is broader than local files: lack of access controls, inadequate encryption, unintentional exposure through logs, error messages or debug features, poor session management, cloud storage misconfigurations, vulnerable third-party libraries and unintended data sharing. The risk applies to any app that holds data worth protecting, which in practice means any app with a login. Neighbouring risks split as follows:

Structure and key requirements

Classify the data first

Storage decisions follow from classification. A practical scheme for mobile apps has four tiers: secrets (refresh tokens, access tokens, private keys, PINs, encryption keys), regulated personal data (health, payment, identity documents), ordinary personal data (names, addresses, message history) and non-sensitive state (UI preferences, feature flags). Secrets go in the platform key store; regulated and personal data go in the app's private storage, encrypted with a key from that store and excluded from backup where appropriate; non-sensitive state can use plain preferences.

Platform storage options compared

Storage locationPlatform protectionSuitable forNot suitable for
Android KeystoreKey material never enters the app process; can be bound to the TEE or StrongBox; use authorisations fixed at creationEncryption keys, signing keys, keys that wrap tokensBulk data (store ciphertext elsewhere)
Android internal storage (files, databases, SharedPreferences)Sandboxed per app; included in Auto Backup by defaultEncrypted personal data; non-sensitive statePlaintext tokens or credentials (Android's own backup guidance says not to store credentials in shared preferences or files)
Android external or shared storageReadable by the user and potentially other appsFiles the user expects to shareAny sensitive data
iOS keychainEncrypted, accessibility class per item, access groups enforced by entitlementsTokens, passwords, small secrets, keysLarge data
iOS app container with Data ProtectionPer-file keys wrapped by a class key; Complete Protection makes files unreadable shortly after lockPersonal data files and databases with an appropriate classSecrets that should not be backed up
iOS NSUserDefaults and plistsApp container default class onlyNon-sensitive preferencesTokens, personal data
Caches, logs, temporary files, clipboard, screenshotsLittle or none; often shared or persisted outside the app's controlNothing sensitiveEverything sensitive
Cloud storage and FirebaseOnly the access rules configured on the serviceServer-held data with owner-based rulesAnything behind open or "any signed-in user" rules

iOS Data Protection classes and keychain accessibility

Apple's Platform Security documentation defines four file protection classes. Class A Complete Protection (NSFileProtectionComplete) discards the decrypted class key shortly after the device locks. Class B Protected Unless Open (NSFileProtectionCompleteUnlessOpen) lets files be written while locked, such as a background download. Class C Protected Until First User Authentication (NSFileProtectionCompleteUntilFirstUserAuthentication) keeps the key in memory after first unlock and is, in Apple's words, "the default class for all third-party app data not otherwise assigned to a Data Protection class". Class D No Protection (NSFileProtectionNone) is protected only by the device UID.

Keychain items carry an accessibility value: kSecAttrAccessibleWhenUnlocked (equivalent to Complete Protection), kSecAttrAccessibleAfterFirstUnlock (for items needed in background refresh), and kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly, which Apple states does not sync to iCloud Keychain, is not backed up and becomes unusable if the passcode is removed. Other ThisDeviceOnly items are protected with the device UID in a backup and cannot be used if restored to a different device. Apple also lists kSecAttrAccessibleAlways as equivalent to NSFileProtectionNone; it should not appear in new code.

Android Keystore features to use

  • Hardware binding: on Android 10 (API 29) and later, check KeyInfo.getSecurityLevel() for TRUSTED_ENVIRONMENT or STRONGBOX to confirm where the key lives.
  • StrongBox: request it with setIsStrongBoxBacked(true) for apps at risk of physical attack, and fall back when the framework throws StrongBoxUnavailableException; StrongBox supports fewer algorithms and is slower.
  • User authentication binding: setUserAuthenticationParameters() with AUTH_BIOMETRIC_STRONG, AUTH_DEVICE_CREDENTIAL or both, either per operation or time based. Biometric-only keys are invalidated when a new biometric is enrolled unless setInvalidatedByBiometricEnrollment(false) is set.
  • Immutable authorisations: algorithm, purpose, padding and block mode restrictions are fixed when the key is generated, so set them narrowly.

Identity and NHI requirements

The most valuable data on most devices is not personal data but the credentials that let the app act on the user's behalf. Those tokens and keys are non-human identities: they authenticate the app instance to the backend, they are long lived, and a copy works from anywhere unless something binds it to the device.

  • Refresh tokens: store in the keychain with a ThisDeviceOnly class or encrypted with a non-exportable Keystore key; never in SharedPreferences, NSUserDefaults, SQLite or a WebView's local storage in plaintext. OWASP's "insecure data caching" scenario is exactly a cached authentication token being reused to impersonate the user.
  • Access tokens: keep short lived and in memory where possible, so there is little to steal at rest.
  • Device-bound keys: where the backend supports it, bind sessions to a key pair generated in the Keystore or Secure Enclave so that a stolen token without the key is useless. See the OWASP Mobile Top 10 M3 Insecure Authentication and Authorization Guide.
  • Third-party SDK keys and tokens: analytics, crash reporting and payment SDKs write their own identifiers and tokens to the app container. Include them in the storage inventory.
  • Server-side revocation: assume a device will be lost or compromised; the backend must be able to revoke a single device's tokens without forcing every user to log in again. The Secrets Management Guide covers the rotation side.

Implementation steps

  1. Inventory what the app stores. Run the app through its main journeys on a test device, then pull the app container (a debug build on Android, a development build on iOS) and list every file, database, preference key and keychain item. Include SDK-created files. This inventory is the baseline for everything else.
  2. Classify each item against the four tiers above and record the required location and protection.
  3. Move secrets into the key stores. Store tokens in the keychain with an explicit accessibility class; on Android, generate a non-exportable AES key in the Keystore and use it to encrypt tokens and sensitive files. Plan a migration away from security-crypto's EncryptedSharedPreferences if it is in use, because its APIs are deprecated.
  4. Set file protection classes. On iOS, write sensitive files with Complete Protection unless a background need is documented. On Android, keep sensitive files in internal storage, never in external storage or shared media collections.
  5. Close the leak paths. Strip verbose logging from release builds (Android's guidance shows R8 -assumenosideeffects rules for android.util.Log), redact sensitive values in toString(), disable keyboard caching on sensitive fields, prevent screenshots and app-switcher snapshots on sensitive screens, clear WebView caches and delete temporary files after use.
  6. Configure backup. Exclude token stores and sensitive databases in Android dataExtractionRules and fullBackupContent, and consider disableIfNoEncryptionCapabilities="true" on cloud-backup. On iOS, use ThisDeviceOnly keychain classes and exclude sensitive files from backup.
  7. Lock down remote storage. Replace open or "any signed-in user" rules with owner-based rules, as Firebase's documentation recommends, and test them with the rules simulator before release.
  8. Roll out in stages. Ship storage changes behind a migration that reads the old location, writes the new one and deletes the old copy, through internal testing then a staged rollout. Keep the old read path for one release so a rollback does not log every user out, then remove it.

Evidence and assessment

M9 testing is mostly dynamic: use the app, then look at what it left behind. MASVS-aligned testing should cover the following.

TestWhat to look forEvidence
App container review after usePlaintext tokens, personal data or keys in preferences, plists, SQLite, Realm or filesFile inventory with classification
Keychain and Keystore reviewAccessibility classes, hardware security level, user-authentication bindingItem list with attributes
Log reviewTokens, personal data or full API responses in logcat or the iOS unified log during login and key journeysCaptured log excerpt (redacted)
Backup and restoreWhether restored data on a second device includes tokens that still workRestore test notes
Caches and snapshotsHTTP cache, WebView cache, keyboard cache, app-switcher screenshots containing sensitive dataScreenshots and cache file list
Logout and uninstallWhether logout deletes tokens and cached data; whether keychain items survive reinstallBefore and after container diff
Remote storageUnauthenticated and cross-user reads against each bucket or database the app usesRequest log and rules version

Metrics:

  • Number of sensitive items found in plaintext storage per release (target zero).
  • Percentage of stored secrets held in the Keystore or keychain with an explicit protection class.
  • Number of sensitive values found in release-build logs during regression testing.
  • Percentage of backend storage locations with owner-based rules verified in the last release cycle.
  • Time from a storage finding to a released fix.

Monitoring on the server side helps too: a token used from two devices or two distant locations at once is a signal that it was copied from storage or backup. The Mobile App Security Testing Guide covers tooling and scoping.

Mapping to other frameworks

FrameworkReferenceRelevance to M9
OWASP MASVS v2MASVS-STORAGE-1, MASVS-STORAGE-2Core controls for intended storage and unintended leaks
OWASP MASVS v2MASVS-CRYPTO-2 "The app performs key management according to industry best practices."Keys in Keystore or keychain
OWASP MASVS v2MASVS-PLATFORM-3 "The app uses the user interface securely."Screenshots, snapshots, sensitive display
OWASP MASVS v2MASVS-PRIVACY-1Store less data in the first place
NIST SP 800-53 Rev. 5SC-28 Protection of Information at Rest; SC-28(1) Cryptographic Protection; SC-12 Cryptographic Key Establishment and ManagementEncryption at rest and key handling
NIST SP 800-53 Rev. 5SI-11 Error Handling; MP-6 Media SanitizationError messages and logs; deleting temporary files and data on logout
NIST CSF 2.0PR.DS-01 The confidentiality, integrity, and availability of data-at-rest are protectedOutcome M9 controls deliver
ISO/IEC 27001:2022 Annex AA.8.24 Use of cryptography; A.8.12 Data leakage prevention; A.8.10 Information deletionEncryption, leak prevention, deletion
CIS Controls v8.1Safeguard 3.11 Encrypt Sensitive Data at RestEncryption of stored sensitive data
MITRE ATT&CK MobileT1409 Stored Application Data; T1533 Data from Local System; T1634 Credentials from Password StoreTechniques that target what M9 protects

Data protection law adds its own obligation: GDPR Article 32 requires security appropriate to the risk and names encryption as an example measure. See the Encryption Guide for the wider context.

Common pitfalls

  • Treating the sandbox as encryption: app-private storage stops other apps on a healthy device, but not a rooted or jailbroken device, a debug build, a forensic extraction or a backup. OWASP names rooted and jailbroken devices as an attack vector for this reason.
  • Hardcoding the encryption key: encrypting a database with a key stored in the APK or in the same preferences file adds work for the attacker but no protection. The key must come from the Keystore or keychain. See the Cryptographic Key Management Guide.
  • Logging during development and never removing it: Android's documentation notes that although reading logcat needs READ_LOGS since Android 4.1, some preloaded apps hold that permission, so logs are prone to leakage. Strip logs at build time rather than relying on reviews.
  • Logout that only clears the UI: tokens, cached API responses and downloaded documents remain in the container. Logout must delete them and revoke the refresh token server side.
  • Forgetting backups: Auto Backup includes shared preferences, internal files, databases and getExternalFilesDir() by default, so a token store left out of the exclusion rules travels to the cloud and to the next device.
  • Open cloud storage behind the app: in the Cybernews study of 156,080 iOS apps, 836 hard-coded bucket instances accepted unauthenticated requests, exposing 406 TB of data, and 2,218 Firebase instances exposed 19.8 million records including session tokens. See the iOS Apps Leaking Hard-Coded Secrets 2025 breach page.

Practitioner checklist

  • Produce a storage inventory per app version, including SDK-created files, and classify every item.
  • Keep refresh tokens and keys only in the keychain or the Android Keystore, with explicit accessibility classes and hardware security levels checked.
  • Encrypt sensitive files and databases with a non-exportable key; never ship or store the key beside the data.
  • Use iOS Complete Protection for sensitive files unless a background requirement is documented.
  • Remove dependencies on deprecated security-crypto APIs from new code and plan migration for existing code.
  • Strip debug and verbose logging from release builds and redact sensitive objects in logging paths.
  • Exclude secrets from Android backup rules and use ThisDeviceOnly keychain classes; test restore to a second device.
  • Delete tokens, caches and temporary files on logout and revoke the session server side.
  • Verify owner-based access rules on every bucket and Firebase database the app uses.
  • Track the five metrics above at each release review.

Standards and references

Related NHI Mgmt Group resources: OWASP Mobile Top 10 Guide · Android App Security Guide · iOS App Security Guide · Mobile Device Security Guide · Firebase Credentials Security Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 26 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.