Safeguard
Security Guides•

Can you hide an API key inside a mobile app?

No. Any key shipped in an app can be pulled out by the person who installs it. Here is what to do instead: a backend proxy, scoped tokens and rotation.

Safeguard Security Team
5 min read

No. Any secret that ships inside a mobile app can be pulled out by whoever installs it, because they hold the binary and the device. Obfuscation slows people down but does not change that. Keep real secrets on your server and give the app short-lived, narrowly scoped tokens instead.

Why an app cannot keep a secret

A mobile app is software you hand to strangers. Each copy can be unpacked, read, run in a debugger and watched on the network. Whatever the app needs at runtime, the person running it can see.

The OAuth standard for native apps says this directly. RFC 8252 states that secrets statically included in an app distributed to multiple users should not be treated as confidential, because one user may inspect their copy and learn the shared secret. The OWASP Mobile Application Security Cheat Sheet gives the same instruction in plain terms: do not hardcode credentials in the mobile app.

So the question is never how well you can hide the key. It is whether the key should be in the app at all.

Which values are safe to ship

Not everything in an app is a secret. The trick is to sort values by what happens if a stranger reads them.

ValueSafe in the app?Why
OAuth client ID for a public clientYesIt identifies the app, it does not prove anything
Your own API base URLYesAnyone watching traffic sees it anyway
Third-party secret or server keyNoIt grants access in your name, with your billing
Signing key or admin credentialNoFull control, no per-user limit
Per-user access token, short livedYes, in secure storageIt is scoped to one user and expires

If a value lets the holder spend money, read other users' data or act as your company, it belongs on a server.

Steps to take a key out of the app

  1. List every outbound call the app makes. Read the network layer and the third-party SDK configuration, not just your own API client.
  2. Mark each call that carries a secret. These are the ones to move.
  3. Add an endpoint on your own backend that makes the third-party call for the app. The backend holds the key and the app never sees it.
  4. Make the app sign users in with the authorization code flow and PKCE, then send the resulting access token to your backend. The backend decides what each user may ask for.
  5. Limit what the backend will do on a user's behalf: allowed operations, request size, and a per-user rate limit. A proxy with no limits is just a longer path to the same abuse.
  6. Rotate the old key. Every published version of the app that contained it is exposed, including old versions still installed on phones.
  7. Restrict the replacement key at the provider if it supports limits by IP address, referrer or scope, and set a spending cap.

What about obfuscation and encryption in the app?

Obfuscation makes extraction slower. Encrypting the key with another key stored in the app only moves the problem one step. Both are fine as extra friction for low value identifiers. Neither is protection for a credential that carries real authority.

The same logic applies to checks the app performs on itself. A tampered app can falsify its own results, which is why Apple's App Attest documentation tells developers they cannot rely on app logic to perform security checks on itself. Decisions belong on the server.

What to do if a key already shipped

Assume it is public. Rotate it, move calls behind the backend, ship the new build, then retire the old key once old versions have mostly aged out or been blocked by a minimum version check. Check the provider's usage logs for activity you do not recognise.

Safeguard's SBOM and dependency scanning covers the libraries inside your mobile builds, which helps you see which SDKs are making direct calls. You can try a free scan at gold.safeguard.sh/scan.

Quick check

Is a client config value or OAuth client ID a secret?

Identifiers meant to name your app are designed to be public, but check what each one can do on its own. If the identifier alone grants access to data or billing, protect it with server side rules or restrictions rather than hiding it.

Can I store the key in the Keychain or Android Keystore instead?

Those stores protect data on a device from other apps. They do not stop the device owner from getting the value after your app has fetched it, and they are for per-user secrets, not for a key shared by every install.

Do I need a backend just to call one third-party API?

If the call needs a secret, yes. A small proxy that authenticates the user and enforces limits is the usual answer.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.