2026-04-02 · 6 min
5 ways vibe coding leaks API keys into the browser
How sites from Cursor, Lovable, and Bolt ship secrets to every visitor, and what to do when it happens.
A key is leaked when a browser can download it. Nobody has to "hack in". These are the five paths we see most often when a site was built in a hurry with an AI coding tool.
1. The variable was named NEXT_PUBLIC_
In Next.js, any env var that starts with NEXT_PUBLIC_ is bundled into the client. Models often suggest that prefix just to make the demo run. A secret the server needs must not use it.
2. It was pasted into a component
The key was in the chat once, so the model wrote it into lib/api.ts or a button handler. Searching the source for sk- or AKIA usually finds it. Moving the string to another file does not help. The bundle still downloads it.
3. .env is gitignored, and the key was copied anyway
Ignoring .env protects that file. It does nothing for the same string hardcoded in a fetch call. People feel safe because the env file never committed, while the client already ships the value.
4. The sample key was never rotated
Bolt, Lovable, and tutorial repos often include a key that "just works". If you launch on it, other people can use it too. Stripe sk_live_ and sk_test_ are not interchangeable. A live key in the client should be revoked now, not later.
5. Production source maps are still on
A production source map hands your original files to anyone. A key that only lived in a comment or an old function can come back through the map. Turn production source maps off for the launch build.
When you find one
1. Revoke the old key at the provider. Deleting the line is not enough. 2. Issue a new key and keep it in the host's environment, read only by a server route. 3. The browser should ask your server to do the job. It should not hold the secret. 4. Run the URL through the free scan and confirm the pattern is gone.
The Full Check writes this class of issue down with a fix. If you no longer know which file to open, add Launch Rescue and we will quote it.