RUScan

Learn / Secrets & API keys

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.

Updated: 2026-11-13·6 min read

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.

Why keys inside an APK are public

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.

Where leaked keys actually hide

  • Resources: res/values/strings.xml and friends, the classic “put it in a config file” spot, greppable without any tools.
  • Assets and configs: assets/config.json, bundled.env files copied by a sloppy build script.
  • DEX constants: string literals in Java/Kotlin code, surviving obfuscation untouched.
  • Native libraries: .so files holding derived or XOR-ed keys; visible to strings and disassembly.
  • Build metadata: forgotten debug endpoints, staging URLs and their basic-auth pairs.

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.

The recovery playbook

  1. Rotate immediately. A leaked key is compromised the moment the APK was distributed; there is no “probably nobody looked”. Rotation is cheap; forensics of what the key did for three months is not.
  2. Check the provider dashboard. Usage spikes, unfamiliar regions, new objects created with the token. Establish whether the leak was theoretical or exploited.
  3. Scope the replacement. Restricted keys tied to specific APIs, referrer/IP rules where the provider supports them, separate keys for dev/staging/prod so the next leak is boring.
  4. Move the secret server-side. The only durable fix: the client holds a short-lived token, your backend holds the key. Whatever the client ships is world-readable; design for it.
  5. Rescan every release. Secrets regress: a library update re-adds a debug key, a teammate reverts the config cleanup. A diff between versions shows exactly which findings are new, which is how you catch the regression before users do.

What the leaked key reveals about the build

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

Does ProGuard/R8 obfuscation protect my API key?

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.

The key is inside native code (.so), am I safe?

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.

What do I do in the first hour after finding a leaked key?

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