An API key is exposed when it reaches code that runs in a visitor's browser or a repository other people can read. In AI-built apps this usually happens because a payment, email or AI key was put in an environment variable whose name tells the build tool to ship it to the browser, such as one starting with VITE_ or NEXT_PUBLIC_. Anyone who opens developer tools can copy it. The fix has three parts: move the call that uses the key onto a server, rotate the key with the provider, and check nobody has used it in the meantime. You can search for exposed keys yourself in under an hour.
This post is for founders and product leads with an app built in Lovable, Bolt, v0, Replit, Cursor or a similar tool. It explains how keys leak, how to find them, how to fix a leak properly, and when to bring in help.
The short answer
Build your app, then search the output folder for the first characters of every secret key you use, along with common prefixes such as sk_, sk-, re_ and sb_secret_. Run a secret scanner over your Git history as well. For each key you find, rotate it with the provider first, then move the code that uses it into a server or edge function. Check the provider's usage logs for calls you did not make.
Which keys are meant to be public
Some keys are designed to sit in the browser. The Supabase publishable key (the anon key on older projects), a Stripe publishable key starting with pk_, and a Google Maps key restricted to your domain are all expected to be visible. Their safety comes from somewhere else: row-level security for Supabase, and restrictions set in the provider’s dashboard for the others.
Secret keys are different. A Stripe secret key, a Resend or SendGrid key, an OpenAI or Anthropic key, and the Supabase secret or service role key all act with full authority on your account. Supabase’s documentation says its secret key bypasses row-level security and must never be placed in a browser or source control. Whoever holds one of these can send email as you, charge or refund through your Stripe account, or run up your AI bill.
How keys leak in AI-built apps
There are four routes we see repeatedly.
Public environment variable prefixes. Build tools copy certain variables into the browser bundle on purpose. Vite exposes anything starting with VITE_, Next.js exposes anything starting with NEXT_PUBLIC_, and Expo does the same with EXPO_PUBLIC_. When an AI builder needs a key to make a feature work in the preview, putting it in one of these is the quickest route, and the key then ships to every visitor. Bolt’s documentation makes the distinction clearly: its Secrets are available only to server functions, while values in the project’s .env file can be read by browser code.
Keys pasted into code. Someone pastes a key into a prompt, and the builder writes it straight into a source file. It then sits in the repository and in the bundle.
Keys in Git history. A key removed in a later commit is still in the history. If the repository was ever public, or is shared with contractors, the old commit is readable.
Keys in logs and error messages. A server function that logs the full request or returns a raw error can echo a key back to the browser or into a logging tool more people can see.
How common this is
GitGuardian scans public GitHub every year. Its State of Secrets Sprawl report, published in March 2025, counted 23,770,171 new hardcoded secrets added to public repositories during 2024, and found that 70% of secrets it first detected in 2022 were still valid when it checked again. These are GitGuardian’s own figures from its own scanning method, and they cover public GitHub as a whole, so read them as a sign of scale rather than a rate for AI-built apps. The second figure is the one to remember: most leaked keys are never rotated.
The checks to run yourself
Set aside an hour. You need the code, a terminal and access to each provider’s dashboard.
- List your keys. Write down every external service the app uses and which key each one needs. Mark each key as public by design or secret.
- Read your environment variables. In your builder or host, list every variable. Any secret with a
VITE_,NEXT_PUBLIC_orEXPO_PUBLIC_name has shipped to browsers. - Search the built bundle. Run your production build, then search the output folder (
distfor Vite,.next/staticfor Next.js) forsk_,sk-,re_,sb_secret_,service_roleand the first six characters of each secret on your list. Anything found is public. - Check the live site. Open your app, open developer tools, and search the loaded JavaScript in the Sources panel for the same strings. Some hosts inject variables at runtime, so the live site can differ from your local build.
- Scan the Git history. Run an open-source scanner such as gitleaks or TruffleHog over the full repository history. It will find keys removed from current files but still present in old commits.
- Turn on push protection. GitHub’s push protection blocks pushes that contain recognised secrets. GitHub’s documentation says it is on by default for your personal account when you push to public repositories, while push protection for a repository has to be switched on. If your host offers build scanning, as Netlify does, leave it on.
- Check provider logs. For each key you found exposed, look at the provider’s usage or API logs for calls from places you do not recognise.
Fixing a leaked key properly
Order matters. Rotate first: create a new key, update the server with it, then revoke the old one. Deleting the key from your code without rotating it leaves a working key in every copy of the old bundle, in caches and in Git history. GitHub’s guidance on removing sensitive data says the same, and treats rewriting history as a secondary step after the credential is revoked.
Then move the code. The call that uses the key goes into a server function: a Supabase Edge Function, a Bolt server function, a Next.js server action or route, a Netlify or Vercel Function, or your Replit app’s server. The browser calls your function, your function checks who is asking, and only your function holds the key.
Finally, limit the damage of any future leak. Use restricted keys where the provider offers them (Stripe does), set spending limits on AI providers, give development and production separate keys, and keep one key per service so a leak means rotating one thing.
What the checks do not cover
Finding and moving keys closes the most expensive leak. It does not check that the new server function verifies the caller, that the database rules are right, or that a function cannot be called a thousand times a minute to run up the same bill another way. A function that forwards any prompt to OpenAI for anyone who asks can cost you as much as the leaked key did.
When to get a second pair of eyes
If you have found a live secret key in a public bundle, rotate it today and then get the rest of the app checked, because the conditions that put it there usually produced other gaps. Our vibe-coded app audit starts at $500, and you get a written report within a week covering keys, database rules, auth, storage, rate limits and backups. Harden starts at $1,000 if you want us to make the fixes, and Rebuild starts at $8,000 for apps that need a proper server layer.
For checks specific to your builder, see Your Lovable app is probably public, Is my Bolt.new app secure?, Taking a v0 app to production, Replit app to production and Cursor app security review. For database rules, see Supabase row-level security for AI-built apps, or go straight to the audit page.
Questions we get asked
My repository is private. Is a key in the code still a problem?
Less urgent, but yes. Everyone with access to the repository, including former contractors and any tool connected to it, can read the key, and a key in the code usually ends up in the bundle too.
Can I hide a key by encoding or splitting it in the front end?
No. The browser has to reassemble the key to use it, so anyone can do the same. Keys that must stay secret belong on a server.
I rotated the key. Do I still need to rewrite Git history?
Once the old key is revoked it is useless, so rewriting history is tidy-up rather than protection. Do it if the repository is public or will be shared.
Which keys matter most?
Anything that can move money, send messages as you or spend on your account: payment, email, SMS and AI keys, and any database key that bypasses access rules.
Sources and further reading
- The State of Secrets Sprawl 2025, GitGuardian, March 2025: 23,770,171 secrets in 2024, 70% of 2022 secrets still valid
- Understanding API keys, Supabase docs, checked 21 November 2026
- Env variables and modes, Vite docs, checked 21 November 2026:
VITE_variables are exposed to client code - Environment variables, Next.js docs, checked 21 November 2026:
NEXT_PUBLIC_inlined at build time - Environment variables in Expo, Expo docs, checked 21 November 2026:
EXPO_PUBLIC_ - Secrets, Bolt support, checked 21 November 2026
- About push protection, GitHub docs, checked 21 November 2026
- Removing sensitive data from a repository, GitHub docs, checked 21 November 2026
- Secret scanning, Netlify docs, checked 21 November 2026
- vibe-coded app audit, the SBD service this post describes















