MASWE-0001: Sensitive Data Stored Unencrypted in Private Storage
Overview
Category: MASVS-STORAGE
Vulnerability: Sensitive Data Stored Unencrypted in Private Storage Locations
CWEs: CWE-312 (Cleartext Storage of Sensitive Information), CWE-922, CWE-200, CWE-732
MASTG Test: MASTG-TEST-0001
MITRE ATT&CK Mobile: T1409 (Access Stored Data), T1533 (Data from Local System)
CVSS v4.0 Score: 7.5 HIGH (CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N)
NIST Standards: NIST SP 800-163 Rev. 1 (Β§4.1), NIST SP 800-53 (SC-28)
Industry Compliance: PCI-DSS v4.0 (Req 3.4), Google Play MASA (Β§1.1)
MASWE-0001 covers vulnerabilities where sensitive information (passwords, auth tokens, session IDs, PII, financial data) is stored in the application's internal private storage directory (/data/data/<package_name>/) in unencrypted plaintext. While Android uses Linux user sandboxing to isolate applications, plaintext data is completely exposed to attackers with root privileges, physical access, ADB backup extraction, or local path traversal exploits.
π Vulnerability Vectors (The "Attacker" Perspective)
Our :app-vulnerable module demonstrates 6 distinct private storage anti-patterns:
- SharedPreferences Plaintext XML: Writing credentials into
shared_prefs/user_session.xml. The data is stored in cleartext XML and easily extracted. - Unencrypted DataStore (Protobuf): Serializing auth tokens into Jetpack DataStore without encryption. Binary Protobuf is NOT encryption.
- Room/SQLite Cleartext Database: Storing credit card PAN and CVV in a standard SQLite database (
.db) and unencrypted Write-Ahead Log (WAL) journals. - Exported FileProvider Root Path: Misconfiguring
<root-path path="/" />infile_paths.xml, allowing malicious external apps to request internal XML files via Content URI. - WebView DOM Storage (localStorage): Enabling
domStorageEnabledallows web scripts to write tokens to unencrypted LevelDB files on disk. - Persistent Cache Files: Creating temporary sensitive PDFs in
getCacheDir()without callingdeleteOnExit().
π Attack Flow Sequence
sequenceDiagram
autonumber
actor Attacker as π Attacker / Malware
participant Device as π± Android Device (Root / ADB)
participant Storage as π /data/data/com.yourapp/shared_prefs/
participant Server as βοΈ Enterprise Backend
Attacker->>Device: 1. Gain root access or initiate ADB backup
Attacker->>Storage: 2. Read user_session.xml or app.db
Storage-->>Attacker: 3. Plaintext JWT & user passwords dumped
Attacker->>Server: 4. Replay JWT token to hijack session
Server-->>Attacker: 5. Full unauthorized account takeover
π‘οΈ Mitigations & Secure Implementation (The "Secure" Perspective)
Our :app-secure module applies defense-in-depth to remediate these vulnerabilities:
- Jetpack Security (EncryptedSharedPreferences): Encrypting keys using AES-256-SIV and values using AES-256-GCM authenticated cipher backed by Android Keystore.
- Tink AEAD over DataStore: Wrapping Jetpack DataStore serialization in an authenticated encryption stream (Aead).
- SQLCipher for Room: 256-bit AES database encryption for all tables, indexes, WAL journals, and temporary files.
- Strict FileProvider Rules: Restricting scopes strictly to
<files-path>or<cache-path>subdirectories with non-guessable filenames. - In-Memory Streaming: Keeping sensitive tokens exclusively in volatile RAM (
StateFlow), wiping on process termination.
π Secure Architecture Diagram
graph TD
subgraph MobileApp ["π± Android App (:app-secure)"]
UI["Compose UI Screen"]
VM["MVI ViewModel (Atomic CAS)"]
Repo["SecureRepository"]
Keystore["Android KeyStore (MasterKey TEE)"]
Tink["Google Tink AEAD"]
SQLCipher["SQLCipher Driver"]
end
subgraph EncryptedDisk ["πΎ Hardware-Secured Storage"]
EncPrefs["EncryptedSharedPreferences (AES256-GCM)"]
EncDB["Room SQLCipher Database (AES256-CBC)"]
end
UI -->|Store Token| VM
VM -->|Execute Mitigation| Repo
Repo -.->|Obtain MasterKey| Keystore
Repo -->|Encrypt Payload| Tink
Tink -->|Write Ciphertext| EncPrefs
Repo -->|Open Cipher Hook| SQLCipher
SQLCipher -->|Write Encrypted DB| EncDB
π§° Verification & Automation Suite (poc/)
The :features:maswe0001 module includes complete automation scripts:
- poc/frida_hook.js: Runtime interceptor capturing SharedPreferencesImpl.getString and EditorImpl.putString calls.
- poc/semgrep_rule.yml: Static analysis rule for CI/CD gates detecting plaintext SharedPreferences and unencrypted DataStore.
- poc/adb_verify.sh: One-line terminal verification inspecting /data/data/.../shared_prefs/ for cleartext credentials.