Skip to main content
All articles

Insecure data storage on Android: CVE-2018-19981 and the token sitting in plaintext

An access token in SharedPreferences, a password in a log, an admin credential on the SD card. Android isolates app storage well, and then the app writes secrets where isolation does not reach, or where a backup carries them off the device. What to check, where each secret hides, and what to use instead.

By Published

8 min read2 views

<map>
  <string name="auth_token">eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...</string>
</map>

That is a real shape of a real problem: a bearer token in a SharedPreferences XML file, in plaintext, on the device. On a standard phone the app's own sandbox keeps other apps out of it. The trouble starts everywhere that sandbox does not reach: a rooted device, a debuggable build, a cloud backup, a log line, the SD card. CVE-2018-19981 is this exact bug in the AWS SDK for Android.

The bug in one distinction

Android gives every app a private directory that other apps cannot read. That protection is real and, as Google's own guidance says, "sufficient for most applications." Insecure storage is not a failure of that sandbox. It is storing sensitive data either in a form the sandbox cannot protect, or in a place the sandbox never covered.

CWE-922, insecure storage of sensitive information, is the umbrella. The specific mistake is almost always one of four: plaintext in the private sandbox (safe until the sandbox is bypassed), data on external storage (never sandboxed), secrets in logs (readable more widely than the file would be), or data swept into a backup (leaves the device entirely). The question is never "is it in my app's folder?" It is "what happens to this secret when the device is rooted, backed up, or lost?"

Why it varies

The severity depends on where the data sits and what it takes to reach it.

Internal storage (getFilesDir(), SharedPreferences, the app's databases) is private per app. Reading it needs root, a debuggable build, or a backup path. Plaintext here is a real finding but a conditional one.

External storage (the SD card, getExternalFilesDir() on older APIs, anything world-visible) has no such protection. Google's guidance is blunt: files there "are globally readable and writable," so "only store non-sensitive information using external storage." A secret written here is exposed to any app with storage access, no root required.

Logs are broader than they look. Google warns that "inappropriate logging of user information could inadvertently leak user data to other applications."

Backups move the data off the device. With android:allowBackup at its default of true, adb backup on a debuggable or rooted device, and cloud backup on any device, sweep up shared_prefs, getFilesDir() and your databases by default. A secret safe in the sandbox is not safe in a backup archive on someone's laptop.

The real CVE

CVE-2018-19981 is in the AWS SDK for Android, versions at or below 2.8.5, classed CWE-312 (cleartext storage). The CognitoCachingCredentialsProvider cached AWS STS temporary credentials in SharedPreferences in plain text. The class's own documentation confirms it persists the identity id and, with a flag, the credentials in SharedPreferences, and says nothing about encryption. Anyone able to read that file could take the credentials and make authenticated requests as the user. NVD's note records the precondition honestly: exploiting it needs root access to the filesystem, which means the finding is real but gated on a compromised or debuggable device. That gate is exactly the distinction above: the SDK relied on the sandbox alone, and the sandbox is the one thing an attacker with the device removes first.

The pattern recurs with the gate removed. CVE-2025-55443 (rated 9.1 by CISA-ADP, CWE-312) covers an Android MDM client that wrote administrator credentials and server connection details in plaintext to log files on external storage. CVE-2025-50862 (CWE-200) is an app shipped with android:allowBackup="true", allowing data exfiltration through adb backup on debug-enabled or rooted devices. Even a hardened feature is not immune: CVE-2025-21041 (CWE-922, SVE-2024-2258) is insecure storage in Samsung's Secure Folder prior to Android 16, fixed by adding proper access control. Same weakness, different distances to the data.

A lab you can build

You need Android Studio's emulator and its bundled adb. No Docker, no physical device. An emulator image without Google Play ships as rootable via adb root, which is what makes the sandbox inspectable.

Build a throwaway app, or use any debuggable APK you own, that writes a token to SharedPreferences:

getSharedPreferences("auth", MODE_PRIVATE)
    .edit().putString("auth_token", "eyJhbGciOiJIUzI1NiJ9.demo").apply();

Install it on the emulator, then read the sandbox from your workstation:

adb root
adb shell run-as com.example.app cat /data/data/com.example.app/shared_prefs/auth.xml
# Or, on a rootable emulator image, straight in:
adb shell cat /data/data/com.example.app/shared_prefs/auth.xml

The token prints in cleartext. run-as works on any debuggable build without root, which is the point: "private" means access-controlled, not hidden; file-based encryption protects the data at rest before the first unlock after boot, but once the device is unlocked the files are readable in clear to the app, to run-as and to root. Now demonstrate the backup path, which needs neither root nor a debuggable flag on older targets:

adb backup -f backup.ab com.example.app     # allowBackup=true is the default
# The archive is a slightly-wrapped tar; shared_prefs and files are inside it.

Then check logs and external storage the way an assessor would:

adb logcat | grep -iE 'token|password|secret|authorization'
adb shell ls -l /sdcard/Android/data/com.example.app/

Android Studio's Device File Explorer shows the same tree in a UI if you prefer to click through it.

Finding it in source

The greps map to the four mistakes.

# Secrets going into SharedPreferences in cleartext.
grep -rnE 'getSharedPreferences|SharedPreferences|\.putString\(' --include='*.java' --include='*.kt' . \
  | grep -iE 'token|password|passwd|secret|key|credential|session|auth|pin'
# Anything written to external storage.
grep -rnE 'getExternalStorageDirectory|getExternalFilesDir|getExternalCacheDir|/sdcard/|Environment\.getExternal' --include='*.java' --include='*.kt' .
# Sensitive values reaching the log.
grep -rnE 'Log\.[vdiwe]\(' --include='*.java' --include='*.kt' . \
  | grep -iE 'token|password|secret|key|credential|auth'
# Deprecated world-readable modes.
grep -rnE 'MODE_WORLD_READABLE|MODE_WORLD_WRITEABLE' --include='*.java' --include='*.kt' .

Then read the manifest. android:allowBackup defaults to true, so its absence is a finding, not a pass. For apps targeting Android 12 (API 31) and above the backup scope is controlled by android:dataExtractionRules; for apps targeting Android 11 and below, and on Android 11 and below, by android:fullBackupContent. Check which secrets those rules exclude, because by default shared_prefs, getFilesDir() and the app databases are all included.

Fixing it

Do not store the secret at all where you can avoid it. Google's guidance is close to this: "If you must use traditional password authentication, don't store user IDs and passwords on the device." Authenticate once and hold a short-lived, service-specific token, so a leaked artefact expires quickly.

Put keys in the Android Keystore. For any key that must persist, Google's guidance is to use the Keystore, which stores key material outside the app's process and, on supported hardware, in a separate secure environment the app never sees the raw bytes of. Encrypt local data with a Keystore-held key rather than writing the data in cleartext.

A note on EncryptedSharedPreferences. The Jetpack Security library that many guides recommend, androidx.security:security-crypto, deprecated all of its APIs in version 1.1.0-beta01 in June 2025, with Google pointing developers to platform APIs and direct use of the Android Keystore instead. If an existing app uses it, it is still better than plaintext; for new code, go straight to the Keystore.

Keep sensitive data off external storage and out of logs. External storage is for non-sensitive files only, and Google's guidance adds that you must validate anything you read back from it as untrusted input. Strip secret values from log statements, and disable debug logging in release builds.

Set the backup rules explicitly. Either android:allowBackup="false", or backup rules that exclude the files holding secrets. Do not leave the default in place and assume the sandbox covers it.

Set android:exported="false" on components not meant for other apps, so a content provider or activity does not become a second door to the data.

Detection

Make storage a build-time check. The greps above belong in CI, gating on secrets reaching SharedPreferences, external storage, or logs. The OWASP Mobile Application Security Testing Guide's storage tests (MASVS-STORAGE) are the reference for what to assert.

Inspect the installed app, not just the source. Pull shared_prefs, the databases and the files directory from a test install and grep them for token and key shapes. What the running app actually wrote is the ground truth; the source shows intent.

Audit the manifest for backup and export. A missing allowBackup, a permissive dataExtractionRules, or an exported component that touches stored data are all findings a static manifest scan catches every build.

Take this away

Android's sandbox is good, and it is not encryption. A secret in plaintext is safe exactly until the device is rooted, the build is debuggable, the backup runs, or the data was written somewhere the sandbox never covered: the SD card, a log, an archive. Store as little as possible, hold keys in the Keystore, keep secrets off external storage and out of logs, and set the backup rules by hand instead of trusting the default.

Further reading

Was this useful?

Share

Tags

  • mobile security
  • secure code review
  • cve analysis
  • detection engineering

Get the next write-up by email

New technical write-ups by email when we publish. No sales sequence, and every email has an unsubscribe link.

Prefer a feed? RSS. How we handle your address: privacy notice.

Comments

Loading comments…

Leave a comment

Comments are read and approved by hand before they appear, so yours will not show up straight away. Your email address is optional, is never published, and is only used if we need to reply to you directly.

0/5000

Related service

Source Code Review

Reading the code for the flaws that black-box testing structurally cannot reach.

If you want to know whether what you have just read applies to your own systems, that is the engagement that answers it.