Key takeaways
- A key compiled into an app is readable by anyone who downloads it – obfuscation slows people down, it does not protect the key.
- Publishable keys (Stripe publishable, Supabase anon with row-level security, Firebase config) may ship; secret keys never may.
- The fix is a thin backend endpoint that checks the user, applies limits and calls the provider with the secret.
- A key that was ever in a shipped build or in git history must be rotated; deleting it from the code is not enough.
Why agents put keys into the app
You ask for "an AI summary feature" or "send a confirmation email". The agent finds the provider's quickstart, which calls the API with a key, and puts that call where the feature lives: in the app. To make it configurable, it reads the key from an environment variable with the prefix your framework exposes to the client – EXPO_PUBLIC_ in Expo, VITE_ in Vite. Those prefixes exist precisely to inline values into the client bundle. The feature works, the demo is happy, and the key is now part of every build.
From the agent's point of view nothing went wrong: you asked for a working feature and got one. The agent has no reason to think about who downloads the binary. You have to.
Extracting a string from an IPA or APK takes minutes with free tools, and watching the app's network traffic through a proxy is even quicker. Treat every value the app knows as public.
Sort your keys: may ship vs. must not ship
Not every key is a secret. Some are designed to be public and protected by rules elsewhere. Ask the agent to list every credential the app and backend use, then sort them with this table:
| Key | May it be in the app? | Condition |
|---|---|---|
| Stripe publishable key | Yes | Payments are created on your server |
| Supabase anon or publishable key | Yes | Row-level security is on for every table |
| Firebase config (API key, project ID) | Yes | Security rules are strict; App Check helps further |
| Maps SDK keys | Usually | Restricted to your bundle ID or package name and signature |
| Supabase service role key, Firebase admin service account | Never | Bypasses all rules – server only |
| Stripe secret key, email and SMS provider keys | Never | Server only |
| OpenAI, Anthropic and other model API keys | Never | Server only, with per-user limits |
| App Store Connect API key, upload keystore, match passphrase | Never | CI secrets only |
If a "may ship" key depends on a condition, verify the condition. A public Supabase key with row-level security switched off is as dangerous as a secret one – our security audit playbook shows how to prove the rules work.
Talk to an AI Code Engineer about shipping your app to the App Store and Google Play.
In a free call we look at what you built, tell you honestly what stands between it and an approved release – and whether you need us at all.
Move secrets behind a backend endpoint
The pattern is always the same: the app calls an endpoint you control with the user's session; the endpoint checks the user, enforces limits and calls the provider with the secret. A serverless function on your existing platform – Supabase Edge Functions, Firebase Cloud Functions, a small API route – is enough. This is a good agent task with a clear brief:
Move the model API call out of the app. - New server function /ai/summarize, requires a valid user session. - Reads the provider key from the server secret store. - Validates input length; rejects requests over the limit. - Per-user rate limit; returns 429 with a friendly message. - Logs request IDs and errors, never prompt or user content. - App calls the function instead of the provider SDK. - Remove the key and the EXPO_PUBLIC_ variable from the app and the repository. List every file you changed.
The limits matter as much as hiding the key. A public endpoint that forwards anything to a paid API without authentication is just a slower way of leaking the key.
Rotate what has already leaked
If a secret was ever in a build that left your machine – TestFlight, an internal track, a store release – or in a commit pushed to a remote, assume it is known. Removing it from the code and rewriting git history does not help: old builds stay on devices and clones exist elsewhere.
- Deploy the backend endpoint and ship an app version that uses it.
- Create a new key at the provider and put it only into the server secret store.
- Revoke the old key. Older app versions that still call the provider directly will break – which is the point. Plan a forced update if many users are on them.
- Check the provider's usage logs for activity you do not recognize.
If the key is being abused right now, revoke first and accept the broken feature. Usage-based bills do not wait for your release.
Keep credentials out of the agent’s reach
Agents read files to understand your project. If a .env file with live keys sits in the repository folder, it can end up in the agent's context, in a generated file or in a commit. A few habits prevent that:
- Keep
.envfiles in.gitignoreand block them in the agent's permission settings – most agents let you deny read access to paths. - Use separate development keys with low limits for local work; production keys live only in the deployment platform.
- Never paste a key into a chat prompt. Point the agent at a secret name instead.
- Run a secret scanner as a pre-commit hook and enable push protection on your Git host.
- Review MCP server configurations: tokens in a committed config file are just another leaked key.
Signing credentials deserve the strictest treatment. The agent can write a CI workflow that references secrets.ASC_KEY by name; it should never see the value. Our playbooks on GitHub Actions for mobile CI and fastlane with an agent show the setup. Our AI Code Engineers handle signing keys in your own accounts as part of the submission service, under ISO 27001-certified processes.
Secrets checklist before release
- Every credential is listed and classified as publishable or secret.
- No secret key in source, client-prefixed environment variables or the built bundle.
- Conditions for publishable keys verified: row-level security on, security rules strict, keys restricted.
- Secret-using features run through authenticated server endpoints with rate limits.
- Keys that were ever shipped or pushed have been rotated and the old ones revoked.
- .env files are ignored by git and blocked for the agent.
- Signing keys and API keys for the stores live only in CI secrets.
- A secret scanner runs before every commit or push.
Frequently asked questions
Is it safe to obfuscate the key inside the app?
No. Obfuscation makes extraction slower, but the app has to use the key at some point, and anyone can watch the network traffic. Secret keys belong on a server.
Is the Supabase anon key a secret?
No, it is designed to be public – but only safe if row-level security is enabled with correct policies on every table. The service role key, in contrast, must never reach the app.
Can I call the OpenAI or Claude API directly from my app?
Not with your own API key. Put a server endpoint in between that checks the user and limits usage. Otherwise anyone can extract the key and run up your bill.
Can you check our app for leaked keys before release?
Yes. Book a free call and an AI Code Engineer walks through your setup with you, or reviews it as part of taking over your release.
Free, 15 minutes, no obligation
Get your app from agent output to approved release.
Our AI Code Engineers take apps built with Claude Code, Codex, Cursor, Lovable, Base44 and co. through signing, CI/CD, store listings and review – in your own developer accounts.
AI tools, store policies and requirements change quickly – always check the current documentation of the tools and stores you use. This article is independent advice and not affiliated with or endorsed by Apple, Google, Anthropic, OpenAI or any other company or product mentioned; all trademarks belong to their owners.