This week a post went viral in a vibe-coding group. A developer had built a booking app for a small studio with AI tools β Cursor and Claude for the code, Supabase for the backend, Stripe for payments, OpenAI and Resend for the rest. It worked. Customers booked. Then someone looked at what the app was actually shipping to every visitor's browser β and found the OpenAI key, the Stripe secret key, and the Resend key sitting in plain text in the JavaScript bundle.
The comments split instantly. Half the thread called it a rookie mistake; the other half pointed out that the same mistake is now being made at industrial scale, by people who never wrote a line of the code that made it. Both sides are right. And that is exactly why this audit matters: AI coding tools are very good at making things work, and very bad at telling you what you just exposed while doing it.
Here is the ten-minute check that would have caught it.
Modern frontend frameworks inline certain environment variables into the JavaScript bundle at build time. That is by design β the browser cannot read your server's environment, so anything the client-side code needs has to be baked into the files it downloads.
In Vite, any variable prefixed with VITE_ is exposed to client code. In Next.js, it is NEXT_PUBLIC_. The prefix is the whole security model: if a variable has that prefix, it is public. If an AI agent (or a tired human) puts an API key behind that prefix, the key ships to everyone who opens the page.
The same thing happens more quietly when a .env file ends up in the deployed folder, or when a key is pasted directly into source code "just to get it working" and never moved. The app works. The tests pass. The key is public.
Your source code can look clean while the built bundle leaks. The bundle is what the browser gets, so check the bundle:
npm run build
grep -r "sk-live" dist/ || echo "no live Stripe key in bundle"
grep -r "sk-" dist/ | head -20
grep -ri "api[_-]key" dist/ | head -20
Any hit is a leak, full stop. It does not matter whether the key "looks" unused β if it is in the bundle, a visitor can read it.
Bots scan the internet for /.env constantly. Check what your deployment returns for the paths that should not exist:
curl -s -o /dev/null -w "%{http_code}\n" https://your-app.com/.env
curl -s https://your-app.com/.env | head -5
The first command should print 404. The second should print nothing. If either shows file contents, your environment file is being served β fix the deployment before you fix anything else. The same test applies to .env.local, config.json, and any backup files sitting in the public folder.
A leaked key with no spending limit is an open wallet. A leaked key with a $20 hard cap is an embarrassing afternoon. Before shipping, open every provider dashboard and confirm:
pk_) in the browser and keep sk_live_ on the server. Restricted keys with minimal permissions beat a full secret key everywhere.
Caps do not prevent leaks. They limit the blast radius, which is the part you can control after the fact.
If a key has ever been in a frontend bundle, a public repo, a screenshot, or a chat log, treat it as compromised. Rotation is unglamorous and it is the only fix:
If you are unsure whether a key was exposed, rotate it anyway. The cost of rotating is minutes; the cost of guessing wrong is someone else's bill.
The durable fix is architectural, not a checklist item: API keys live on the server, and the browser talks to your server instead.
// Don't do this in the browser:
const res = await fetch("https://api.openai.com/v1/chat/completions", {
headers: { Authorization: `Bearer ${import.meta.env.VITE_OPENAI_KEY}` },
});
// Do this instead β the key stays in an edge function:
const res = await fetch("/api/chat", {
method: "POST",
body: JSON.stringify({ message }),
});
The /api/chat endpoint β a Supabase edge function, a Vercel serverless function, a tiny Express route, whatever your stack offers β holds the key, validates the request, and calls the provider. The browser never sees the key at all. This is the one structural change that makes checks 1β4 mostly unnecessary.
Two habits make it stick:
The reason this story hit a nerve is not that one app leaked three keys. It is that the failure mode is invisible to the person shipping the app. The AI agent did exactly what it was asked to do: build a working booking app. Security review was never part of the prompt, so it never happened.
That is the gap vibe coding creates. The tools compress the time from idea to working software from weeks to an afternoon β but they do not compress the review. The review is still your job, and it is the part that cannot be skipped just because the building got faster.
Ten minutes, four checks, before every deploy. The app you ship next will work just as well β and this time, only you will hold the keys to it.
β Davis George Β· zhuan.xyz