Why it matters

A lost, shared or compromised device puts every file the app wrote next to an attacker, and backups and device transfers copy them further. Storage protection is what keeps a session token or account data from outliving the device the user trusted.

How to meet it

  • Keep credentials in the platform keystore: the iOS Keychain with a ThisDeviceOnly accessibility class, or data encrypted with a non-exportable Android Keystore key.
  • Write other sensitive files only to app-private storage, with explicit file protection on iOS.
  • Never store sensitive data in UserDefaults, SharedPreferences or public folders in the clear.
  • Store as little as the feature needs, and expire local copies.

MASTG tests in the local projects

The local projects run these OWASP MASTG v2.0.0 tests for MASVS-STORAGE-1, as tests you can repeat on your own machine.

MASTG testPlatformProject
MASTG-TEST-0299: Data Protection Classes for Files in Private StorageiOSKeep an iOS app's storage, links and web bridge in bounds · StorageTests
MASTG-TEST-0300: References to APIs for Storing Unencrypted Data in Private StorageiOSKeep an iOS app's storage, links and web bridge in bounds · StorageTests
MASTG-TEST-0301: Runtime Use of APIs for Storing Unencrypted Data in Private StorageiOSKeep an iOS app's storage, links and web bridge in bounds · StorageTests
MASTG-TEST-0302: Sensitive Data Unencrypted in Private Storage FilesiOSKeep an iOS app's storage, links and web bridge in bounds · StorageTests
MASTG-TEST-0207: Runtime Storage of Unencrypted Data in the App SandboxAndroidRepair an Android app's links, components, network policy and storage · StorageTests
MASTG-TEST-0287: Runtime Storage of Unencrypted Data via the SharedPreferences APIAndroidRepair an Android app's links, components, network policy and storage · StorageTests

Guides on this site

Practice

References

  1. MASVS-STORAGE-1 (OWASP MASVS v2.1.0)
  2. MASVS-STORAGE: Storage (OWASP MASVS v2.1.0)

List data from the publisher. A guide is listed as the main subject when the weakness or risk is what the guide is about, and as covering it when a dedicated section or worked example addresses it.

Control statements are quoted from OWASP MASVS v2.1.0, licensed CC BY-SA 4.0; the rest is this site's summary. MASTG tests are those the iOS and Android projects here run, with their titles from mas.owasp.org. License.