API keys leak from AI-built apps when a secret ends up in code that runs in the browser, where anyone who opens the app can read it. Some keys are designed to be public and are fine there. If a secret key has shipped to the browser, treat it as exposed, move the code that uses it to your server, and rotate the key the same day.
Which keys are safe in the browser?
Payment and database providers often issue two kinds of keys. A publishable key identifies your account and can do only limited, low-risk things. A secret key can act as your account. The providers say which is which, so check their documentation before you put any key in front-end code.
| Provider | Safe in the browser | Server only |
|---|---|---|
| Stripe | Publishable keys, starting pk_live_ or pk_test_ | Secret keys (sk_), restricted keys (rk_) and webhook signing secrets |
| Supabase | The publishable key (sb_publishable_, or the legacy anon key), limited by row level security | The secret key (sb_secret_, or the legacy service_role key), which bypasses row level security |
| Any other API | Only keys the provider's docs say are safe to expose | Everything else |
Stripe's API keys documentation says only publishable keys are safe to expose outside your back end, and that keys should never sit in source code or configuration files checked into version control. Supabase's API keys documentation says its publishable key reaches only what row level security allows, while a secret key bypasses every policy and should never go in a browser, a shipped app or source control. That makes the publishable key only as safe as your policies, which is why the Supabase row level security guide matters here too. Moltbook showed what happens otherwise. Wiz found a Supabase key in its client-side code with no row level security behind it, which gave anyone read and write access to the production database, according to Wiz's write-up on Moltbook.
How do secrets end up in the browser?
It happens often enough that scanning vendors now measure it. Escape, which sells API security scanning, passively scanned more than 5,600 live vibe-coded apps and reported over 400 exposed secrets, noting that Supabase service keys were often easy to pull from front-end bundles, in its methodology write-up. Escape's own pages disagree on the sample size, and it calls its results lower-bound estimates. Here are four common ways secrets get there.
A public prefix on a secret variable
Build tools decide what reaches the browser by the variable's name. The Next.js guide to environment variables says variables stay on the server unless they start with NEXT_PUBLIC_, and those are written into the JavaScript bundle at build time. Vite's guide to env variables says variables that start with VITE_ are exposed in client-side code and should not hold sensitive information such as API keys. Add the prefix to a secret to make an error go away, and the secret ships with the next build. Vercel says v0 now checks for misuse of NEXT_PUBLIC_ variables that leak production credentials, in its post on v0 security.
Calling a paid API straight from the page
The quickest way to make an AI, email or payment feature work is to call the provider from the browser. That puts the provider's key in the page, where any visitor can copy it and use it on your account. The call needs to go through your server instead.
Hardcoded defaults and copied examples
AI models tend to reuse the same placeholder secrets. Invicti, which sells application security testing, generated 20,656 web apps with several models and found the hardcoded secret supersecretkey in 1,182 of them. In one app, a predictable token-signing secret let the researcher forge an admin token, as he describes in Invicti's analysis of 20,000 vibe-coded apps.
Commits, configs and your own tools
Secrets also leak through code history. GitGuardian, which sells secrets detection, counted 28.65 million new hardcoded secrets in public GitHub commits in 2025, up 34%, in its State of Secrets Sprawl 2026 report. Secrets for AI services alone reached 1,275,105, up 81%. It found that commits co-authored by Claude Code leaked secrets at 3.2%, against a 1.5% baseline, while noting that developers still decide what gets pushed. It also found 24,008 unique secrets in MCP configuration files, the files that connect AI tools to other services, and 2,117 of them were valid. Your coding tools matter as well. Check Point found flaws in Claude Code, patched before publication, that let malicious project files run code and steal API keys, per Check Point Research.
How do you check your own app for exposed keys?
- Search what the browser loads. Open your live site in a private window. In the developer tools, search across all loaded files for sk_live, sk_test, rk_live, sb_secret_ and the word secret.
- Watch the network traffic. Use the app with the Network tab open, and look at request headers and addresses for keys sent to outside services.
- Compare long tokens with your dashboard. Supabase's legacy keys are long tokens that begin with eyJ. If you find one, compare it with the keys in your Supabase dashboard to see which key shipped.
- Search the whole repository history. Old commits keep old keys, so scan every branch and commit, along with today's code. A secrets scanner does this faster than a person.
- Check the side channels. Look at build logs, preview deployments, error-tracking tools, MCP configuration files and any chat where someone pasted a key. Next.js warns that .env files should almost never be committed to your repository.
What to do when a key has leaked
Assume someone copied it, and assume it still works. GitGuardian found that more than 64% of secrets that were valid in 2022 were still valid when it retested them in January 2026. Deleting the key from your code does not stop anyone who already has it.
- Stop the leak, then rotate right away. Move the code that needs the key to your server and deploy, so the new key cannot leak the same way. Supabase's advice is to rotate a leaked key as soon as you fix the cause. If the key is being abused right now, rotate first, even if a feature breaks.
- Expire the old key now. In Stripe, rotating a key revokes it and creates a replacement. The Dashboard can keep the old key working for up to 7 days to avoid downtime, so for a compromised key, choose to expire it immediately, as Stripe's key rotation steps describe.
- Check for misuse. Stripe lets you view the request logs for each key. Check your other providers' usage and billing pages too, and your database logs for reads or writes you did not make.
- Clean up every copy. Remove the key from the code, the Git history, build logs and AI tool configs.
- Write it down. Record what leaked, when, what it could reach and what you changed. If customer data may have been reached, follow your incident response plan.
How to move secrets to the server
The pattern is short. The browser asks your server, and your server holds the key and calls the provider.
- Store secrets in your host's secret storage, or in server environment variables without a public prefix. Stripe recommends a secrets vault from your hosting platform, with environment variables as the fallback.
- Move every call that needs a secret into a server route, API endpoint or edge function.
- Check who is asking on every server route. A route that anyone can call without signing in hands the provider's power to whoever finds it.
- Use the narrowest key that works. Stripe recommends restricted keys with only the permissions each part needs, and Supabase recommends a separate secret key for each backend component, so one leak means one rotation.
- Keep webhook signing secrets on the server too. Stripe notes they are separate from API keys, and your server uses them to confirm each webhook really came from Stripe.
- Limit where keys work. Stripe lets you attach access policies so a key works only from your known servers, and it notifies you when it blocks a request.
- Put rate limits on routes that spend money, such as AI model calls.
- Add a secrets scanner to your repository, so new leaks are caught before they are pushed.
- Put the rule in your prompts and project instructions. Secrets stay on the server and never get a public prefix. Lovable's security docs say it detects keys pasted into chat and helps you store them in Secrets instead of in your code.
Where to go from here
Search your live bundle today. It is the quickest check in this article, and it tells you whether you have a key to rotate. Then take the free 2-minute self-check to see what else to look at, and work through the pre-launch security checklist.
Our Compliance Readiness Review checks the places AI-built apps slip, secrets in the browser and the repository among them, and ties every finding to the SOC 2, HIPAA or PCI DSS requirement it affects. You can read how we work with apps built with AI coding tools first.