DEV Community

Mohammad Taha Azizi Ahad
Mohammad Taha Azizi Ahad

Posted on

Your App's Private Storage Is Not Private Enough

Android's sandbox makes a promise that sounds absolute: one app cannot read another app's private files. And for the most part, the promise holds. Without root, no app can open your /data/data folder. That is true, and it is also not the whole story — because the real leaks in Android apps almost never come from someone breaking the sandbox. They come from the app handing its own files out the front door.

I learned this the uncomfortable way, by auditing my own messenger app and finding the holes in it myself. The sandbox was never the problem. My own exported surfaces were.

The holes you build yourself

The classic one is path traversal in file sharing. Your app accepts a file from another app, and it saves that file using the name it was given — without checking the name. An attacker sends a file named ../../databases/session.db, your app writes it where the name points, and suddenly a file that arrived from outside has overwritten something private. This is the Dirty Stream pattern Microsoft documented in 2024, and it hit real apps like file managers and office suites, not toy examples.

Then there is the file:// trap. Your app accepts a file URI from an intent, opens it, and sends the content onward — to a server, to another app, to a chat partner. An attacker hands you a URI that points at your own app's private file, and your app faithfully delivers its own session token to the attacker. The app did exactly what it was told. That is what makes it so hard to spot in review.

And there is the Content Provider. A provider that is exported without a permission, or with a query that concatenates user input straight into SQL, is an open door into your database. The 2025 CVE-2025-48544 case showed an attacker reaching other apps' files and databases through exactly this, with no special permissions at all.

What I actually changed in my own app

The fixes are not exotic. They are the boring checks that are easy to skip when you are moving fast.

Session tokens live only in private storage, encrypted where possible, never on external storage, never in Android/data, never in a backup, never in a log line. If a token is in a log, it is already leaked — logs get uploaded, pasted into bug reports, and synced to places you forgot about.

I stopped accepting file:// URIs from other apps entirely, and I never hand a private file path to a FileProvider. File names from intents get validated: no ../, no absolute paths, no characters I did not expect. Content Providers are not exported unless they have to be, and when they are, they sit behind a permission and use parameterized queries.

The mindset shift is the real fix: stop asking "can another app break into my sandbox?" and start asking "what have I already handed out?" On a modern, unrooted phone, the sandbox is the strongest wall you have. The doors are the ones you built into it yourself — and those are the ones worth locking.

Top comments (0)