Skip to content

Lesson 6 of 13 · 11m

There Are No Secrets in the Binary

Every constant you ship is extractable in minutes, so mobile OAuth runs PKCE without client secrets and privileged keys live server-side — obfuscation renames names, never data.

Anything shipped is public

strings classes.dex | grep -i 'api_key' works. So does strings on the Mach-O, jadx's resource view of strings.xml, or the hex view of google-services.json sitting in assets/. There is no layer of the artifact the user can't read — you gave them the file.

The wrong model is thinking of the shipped binary as your code running on a friendly machine. It is a document in the adversary's hands. Whatever constant you put in it — an AWS access key, a service-account JSON, a Stripe secret key, an OAuth client_secret — is extracted within hours by the bots that scrape Play Store APK strings for exactly those patterns. Researchers at Iowa State and Zimperium have published study after study finding live cloud credentials in shipping apps; the credential-scraping pipeline is industrialized, not theoretical.

The Firebase test

The clean way to learn this is google-services.json. The file embeds a client[0].api_key[0].current_key — a Google API key in plaintext — and Google documents it as not a secret: it identifies the project; access control lives in Firebase Security Rules, not in the key. If your Firestore rules are allow read, write: if true, the "leak" isn't the key — it's that your rules let anyone holding it dump the database. Pentesters check https://<project>.firebaseio.com/.json first for a reason.

So the real question for every embedded key isn't "is it in the binary" — it already is — it's "what does possession of this key buy?" If the answer is nothing beyond identifying the project (Firebase, Google Maps), the key is a public identifier and your energy belongs in Rules and restrictions. If the answer is "read/write things other users' data" — S3 creds, a service account, an API token with account scope — the key was never supposed to be in the app.

What obfuscation doesn't do

R8 renames classes to a.b.c and strips dead code. String constants survive verbatim — obfuscation changes names, not data. DexGuard's string encryption decrypts at runtime inside the process on the user's device, which is precisely where Frida/objection operate. The decryption code ships with the ciphertext and the key material needed to decode it; you are shipping a locked box welded to its key. It raises the reading cost by an afternoon. It does not make a secret.

OAuth on a phone

RFC 8252 exists because of this problem: native apps are public clients — they cannot hold a client secret, and embedding one is explicitly wrong. The flow is Authorization Code + PKCE via ASWebAuthenticationSession (iOS) or a Custom Tab (Android), with the redirect bound to a verified Universal Link / App Link — never a custom scheme, which any app can squat on (the scheme-hijack interception attack from module one). If your backend expects a client_secret from a mobile app, the backend's threat model is broken, not the client's.

The architecture that works

Privileged operations go server-side. The app authenticates the user, the server holds the service credential — the app calls your API, your API calls AWS/Stripe/Firebase Admin with the real key. Keys that must live client-side get scoped to what possession buys:

  • Google Maps and friends: apply application restrictions — Android keys bind to package name + SHA-1 of the signing cert; iOS keys bind to bundle ID.
  • Firebase: the API key stays; you harden Security Rules, enable App Check to gate calls to attested clients, and never put the Admin SDK anywhere near the app.
  • Anything with account-level scope: it belongs on your server, full stop.

Practice

Grep your own release artifact before the scrapers do: apktool d + rg -i 'key|secret|token|BEGIN.*PRIVATE' over smali and assets; strings over .so and Mach-O slices. If a real credential ever shipped, assume it was harvested the day it hit the store — rotate it, don't just remove it next release. Then move the privileged call behind your API and scope what remains client-side. The rule isn't "hide secrets better." It's "ship nothing worth stealing."

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.