Gate/AI Articles

Why shipping secrets in your app is a terrible idea

Secrets and private tokens should never be present in a shipped mobile binary. It's trivial for hackers to steal them.

Animated preview of shipping secrets article
Gate/AI Team 6 min read

TL;DR: If you put API or Auth keys in a shipped mobile app, they will leak. Once they do, your usage is hijacked, costs skyrocket, and when you finally figure out what happnened, you can’t rotate your secrets without cutting off all of your existing installs. There’s a better way that keeps secrets off-device while staying simple: Gate/AI.


What is a “secret”?

  • Provider API keys (e.g., OpenAI, Stripe, SendGrid, etc.)
  • OAuth client secrets, signing keys, HMAC salts
  • Long-lived tokens, refresh tokens, service account JSON
  • Any “Hidden” configuration that would enable misuse if revealed

If it grants power or the ability to spend dollars when presented to a third party, it’s a secret. If it lives on a user’s device, assume an attacker can get it.


How do secrets leak from mobile apps (even “obfuscated” ones)?

It’s surprisingly easy for an attacker to get access to information on your app.

Static Analysis

APKs/IPAs can be unpacked and then strings and resources in the package are extracted with common tools. Code obfuscation only slows down novices. Decompilers + AI make it very easy to turn gobblygook into readable code.

Traffic Inspection

Attackers can simply proxy device traffic going off the phone! You don’t even need to jailbrake or root your phone to harvest tokens.

It can’t be overstated: this is absolutely trivial. It’s particularly common for APIs to pass the authentication key as a URL parameter or request header.

Runtime Hooking

Tools like Frida/Xposed can work on a running app to intercept method calls, patch return values, and dump memory—even with certificate pinning.

Logs & Crash Reports

In-app logging of headers or payloads will leaks keys. Any analytic data or device backups can, as well.

Supply-chain Attacks

Compromised 3rd party dependencies can go quite far in what they can see. If your app includes a hacked dependency, it can see anything your app can.

The bottom line is that anything found in the client is user-controlled. If the app can present a secret, so can an attacker.


What does it cost you when a secret key leaks?

Unlimited abuse on your dime. Keys get plugged into scripts and farmed from cloud VMs. Your next bill will make you cry!

Account bans & reputation hits. Providers may suspend you for abusive patterns from a leaked key.

Cutoff customers You can rotate in a new key, but older installs still carry the old one. All those users will be negatively affected. Not everyone has auto-update turned on.

Security & legal exposure. If a leaked key grants access to user data, you may face incident response and compliance fallout.

Increased customer support You’ll spend cycles chasing fraud, failed requests, and writing hotfixes instead of shipping features.


“But I’ve added protections…”

Many common recommendations to “secure” your app don’t do much to protect secret keys.

  • “We use code obfuscation.” This just slows down but doesn’t stop hackers. Attackers can target running apps, not just strings.
  • “We use cert pinning.” Hooking frameworks can bypass pinning on compromised devices.
  • “We’ll hide it in the Secure Enclave/Keychain/Keystore.” Those protect at rest. But, if your app can read it at runtime, so can a hooked process.
  • “Our key is scope-limited.” Better than nothing, but still spendable and abusable when stolen.
  • “This SDK told me to paste a key in.” Some SDK keys are intentionally public identifiers. Many others are true secrets—know which is which.

How do I solve this problem?

You need an AI Gateway. But guess what? The ones that exist are terrible for small mobile dev teams!

  • They try to solve all of the possible problems in the world. So they are insanely complex to setup.
  • They assume you already run in the cloud, understand networking, and can quickly wire-up IAM, VPCs, DNS, certs, and CI/CD.
  • You pay in setup time, mental overhead, and ongoing operations.

If your goal is “call OpenAI safely from my app,” you shouldn’t have to become your own platform team. Life is too short to be a sys admin!

But here’s the kicker: they still make you ship secrets in your app to authenticate with the gateway! 🤦‍♂️ So yes, you’ll be able to keep your OpenAI key out of your app. But you’ve still left your door open!


A simpler path: keep secrets off-device with Gate/AI

Gate/AI is purpose-built for mobile apps that want to call third-party APIs securely—without shipping secrets and without building a backend.

At a high level:

  • Secrets live in the cloud. Your provider keys never touch the app or the user’s device.
  • Your app calls Gate/AI with newly available, mobile security protocols.
  • Gate/AI enforces policy (allowed endpoints/models, quotas, rate limits) and proxies the call to the provider.
  • Short-lived, scoped access ensures a stolen app binary or intercepted request can’t mint unlimited spend.
  • Rotation & revocation happen centrally—no app update required.

This gives you the safety properties of a backend with the simplicity of an SDK call.

Think: “a minimal, security-first shim between your app and the provider,” so you ship features fast and sleep at night.


A practical security checklist

Use this before you ship your app:

  • No long-lived provider secrets in the app bundle or at runtime
  • Make sure any issued tokens have short lifetimes
  • Make sure you can enforce quotas & rate limits down to the device and user.
  • Keep request logs, track error rates & token consumption
  • Make it easy to rotate and revoke your keys
  • Optional: device attestation/risk signals to throttle abuse

If you can’t tick these boxes, your key will eventually leak—and you’ll pay for it.


Wrapping-up

Shipping secrets in a mobile app is like leaving your credit card on a park bench with a note that says “please don’t use.” It might work for a while—until it doesn’t. The secure (and simpler) path is to keep secrets off-device and enforce policy before requests hit the provider.

If you want that without building and running your own backend, try Gate/AI. You focus on building features; it handles the security.