An API key leaked in your Android app: what to do now
Why obfuscation does not protect keys inside an APK, how leaked tokens get found in minutes, and the recovery playbook: rotate, scope, move secrets to the backend.
Why obfuscation does not protect keys inside an APK, how leaked tokens get found in minutes, and the recovery playbook: rotate, scope, move secrets to the backend.
It starts with a message from security, a bounty report, or your own audit: strings.xml line 142 contains a live Stripe key. An API key shipped inside an APK is public: treat the moment it entered the build as the moment it leaked. Here is why it happens, how it is found, and what to do next.
An APK is a ZIP archive that every user’s phone receives in full. Anyone, no special skills required, can open it, and everything the app ships is in that archive: resources, DEX bytecode, native libraries, assets. The question is how long extraction takes: a plaintext string in resources takes seconds, an obfuscated constant a minute, a key baked into a native library takes one strings command longer.
The natural first reaction, “we will obfuscate”, does not survive contact with how extraction actually works. Obfuscators rename your classes; the string sk_live_… remains a string. Automated secret scanners pattern-match token shapes (sk_, ghp_, Google API keys, JWTs, AWS access IDs) across decompiled sources, resources and binaries in one pass. A demo we run publicly finds an npm token, a Slack webhook and a Firebase key in a sample app within seconds of upload. That pass runs on your build too; see what it finds before the next release ships.
res/values/strings.xml and friends, the classic “put it in a config file” spot, greppable without any tools.assets/config.json, bundled.env files copied by a sloppy build script..so files holding derived or XOR-ed keys; visible to strings and disassembly.Each location needs a different extraction step, which is why serious scanning covers all of them: resources, decompiled Java, native binaries and assets in one report, with severity and the exact file:line as evidence.
Beyond the immediate damage, embedded secrets are a diagnostic: they mark where the boundary between client and backend was left unguarded. A Firebase key plus a Slack webhook plus an npm token in one build says the team treats the APK as a private artifact. The mindset fix matters more than the rotation. Related reading: how analysts use embedded secrets when dissecting malware, and which package formats expose which files.
Frequently asked
No. Obfuscation renames classes and methods, but a string constant stays a string constant. Any grep over the decompiled sources (or over the raw DEX) finds 'sk_live_' style tokens regardless of how the code around them is obfuscated.
Marginally safer against grep. A key baked into a native library is extracted with 'strings libapp.so' in seconds unless it is derived at runtime, and derivation logic is visible to anyone who opens the binary in Ghidra.
Rotate it at the provider, check the usage/billing dashboard for unfamiliar activity, and scope the replacement (restricted key, IP/referrer rules, separate dev and prod keys). Then find every other copy: static analysis of the APK surfaces all embedded secrets with file:line evidence, not just the one you already know about.
From other categories