Skip to content

Guides · VibeVigil

Is My API Key Safe in My Expo or React Native App? (Short Answer: No)

Put an OpenAI, Anthropic or Stripe key in your mobile app's .env file? Anyone who downloads the app can pull it out. Here's how to check your Expo or React Native app, move the key to a server, and stop a surprise AI bill.

Not sure your app is safe? Run a free scan first.
VibeVigil checks your live web app and backend for exposed keys, Supabase tables a stranger can read, missing security headers, SSL problems and downtime. Every issue comes with a ready-to-paste prompt for your coding agent.
Scan my app for free → (only scan apps you own)

Note: the scan looks at public websites, not app store files. Use the steps below to check your mobile app itself.

Is My API Key Safe in My Expo or React Native App? (Short Answer: No)

You built a mobile app with Claude Code, Cursor, Bolt or another AI tool. It calls OpenAI, Anthropic or Gemini. The key sits in a .env file, so it feels hidden.

It is not hidden. When you build the app, that key gets copied into the app itself. Anyone who downloads your app can unpack it and read the key. Then they can use your key, and you pay the bill.

This guide shows you how to check your app in 10 minutes and how to fix it. Only test apps you own.

The short answer

  1. A .env file does not hide a key in a mobile app. At build time, the value is pasted into your app's code.
  2. Expo says this plainly. Do not put private keys in EXPO_PUBLIC_ variables, because "these variables will be visible in plain-text in your compiled application" (Expo: Environment variables).
  3. React Native says the same. "Never store sensitive API keys in your app code" (React Native: Security).
  4. The fix: the app talks to your server (for example a Supabase Edge Function). Only the server holds the secret key and calls the AI provider.
  5. If the key was ever in a released build, treat it as leaked. Make a new key and turn off the old one.

Why "it's in .env" doesn't help

On a website, people expect that the browser can see the code. On a phone, the app feels like a sealed box. It isn't.

  • An Android app (.apk or .aab) is a zip file. The JavaScript lives inside it.
  • An iPhone app (.ipa) is also a zip file with the JavaScript inside.
  • Expo replaces process.env.EXPO_PUBLIC_... with the real value when it builds your app (Expo docs). So the key ends up as plain text in the bundle.

Even Expo's "secret" setting in EAS won't save you here. Expo says secrets "do not provide any additional security for values that you end up embedding in your application itself" (Expo: EAS environment variables).

Which keys are OK in the app, and which are not

KeyOK inside the app?Why
Supabase anon or publishable key (sb_publishable_...)YesIt's made to be public. Row Level Security (RLS) protects the data. (Supabase: API keys)
Supabase service_role or secret key (sb_secret_...)NoIt skips RLS. Whoever has it can read and change your whole database.
OpenAI key (sk-...)NoAnyone can run up your bill.
Anthropic key (sk-ant-...)NoSame: they use it, you pay.
Stripe secret key (sk_live_...)NoIt can create charges and refunds. Only the publishable key (pk_live_...) goes in the app.
Any key named "secret", "private" or "admin"NoIf the name says secret, keep it on a server.

Test 1: Look at your env variables (3 minutes)

Open your project and search for EXPO_PUBLIC_ (or the env tool your app uses, like react-native-config or react-native-dotenv).

For each one, ask: Would I be OK if a stranger saw this value?

  • An API URL or the Supabase anon key: fine.
  • Anything from the "No" rows above: problem.

Also search your code for key patterns, in case the AI pasted one straight into a file:

grep -rnE "sk-ant-|sk-[A-Za-z0-9_-]{20,}|sk_live_|sb_secret_|service_role" --include=*.{js,ts,tsx,json} . --exclude-dir=node_modules

Test 2: Check the built app (5 minutes)

This shows what a stranger would see. Build or export your app, then search the output.

Expo:

npx expo export --platform android
grep -raE "sk-ant-|sk-[A-Za-z0-9_-]{20,}|sk_live_|sb_secret_" dist/

Any Android build you own: rename the .apk to .zip, unzip it, and search the files inside assets/ the same way.

If the search finds a real key, it's in your app. Anyone with the app can find it too.

Test 3: Check who has been using the key (2 minutes)

Log in to your AI provider's dashboard and look at usage by key. Look for:

  • Spikes at odd hours
  • Models your app doesn't use
  • More requests than you have users

If you see any of that, go straight to the fix below and rotate the key first.

The fix: put a small server in the middle

React Native's docs suggest this exact setup: a small server function sits between your app and the paid service, and it holds the key (React Native: Security).

If you already use Supabase, an Edge Function works well:

  1. Move the key to the server. Save it as a function secret, not in the app (Supabase: Function secrets).
  2. Make the app call your function instead of OpenAI or Anthropic directly. The app sends the user's login token.
  3. Check the user in the function. Reject calls that have no valid logged-in user (Supabase: Securing Edge Functions).
  4. Add limits. Cap how many AI calls each user can make per hour or day (Supabase: Rate limiting Edge Functions). Our guide on rate limiting AI features walks through it.
  5. Set a monthly spend limit in your AI provider's dashboard. If something goes wrong, you get cut off instead of a huge bill.

Then rotate the old key

Moving the key isn't enough if an old build already shipped with it. People who installed that version still have the key on their phones.

  1. Create a new key and save it only on the server.
  2. Turn off (revoke) the old key.
  3. Ship the app update that calls your server.

Heads up: old app versions that called the AI provider directly will stop working once you revoke the old key. That's the point. Ask users to update.

Step-by-step help: How to Rotate a Leaked API Key.

Prompt for your coding agent

Copy this into Claude Code, Cursor, Bolt or your AI tool:

My mobile app (Expo / React Native) calls an AI provider directly with an API key stored in an EXPO_PUBLIC_ (or similar) env variable. That key is visible to anyone who unpacks the app. Please:

1. Find every place the app uses a secret key (OpenAI, Anthropic, Gemini, Stripe secret, Supabase service_role or sb_secret_). List them for me first.
2. Create a Supabase Edge Function (or a server route) that makes the AI call. Read the API key from a server-side secret, never from the app.
3. In that function, require a valid Supabase user token and reject requests without one.
4. Add a per-user rate limit (for example, max N requests per hour) and return a clear error when it's hit.
5. Change the app to call this function instead of the AI provider. Remove the secret key from all EXPO_PUBLIC_ variables, .env files used by the app, and the code.
6. Keep only public values (API URL, Supabase anon/publishable key, Stripe publishable key) in the app.
7. Tell me which keys I must rotate in the provider dashboards and where to set the new secret.

Do not turn off Row Level Security and do not put the service_role key in the app.

Quick checklist

  • [ ] No secret key in any EXPO_PUBLIC_ variable or app .env file
  • [ ] Searched the built app and found no keys
  • [ ] AI calls go through my own server or Edge Function
  • [ ] The function checks that the user is logged in
  • [ ] Each user has a rate limit
  • [ ] My AI provider account has a monthly spend limit
  • [ ] Any key that ever shipped in a build has been rotated
  • [ ] RLS is on for my Supabase tables (the anon key in the app is only safe with RLS)

Related guides


Does your app have a web version or a Supabase backend? VibeVigil checks the public side for exposed keys, open Supabase tables, headers, SSL and uptime, and gives you a fix prompt for each issue. Run a free scan → (only scan apps you own)

Scan your app free. It checks the public page of a site you own. No account.

Is My API Key Safe in My Expo or React Native App? (Short Answer: No) · VibeVigil