Before You Ship That Vibe-Coded App, Run This 10-Minute Secrets Audit
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.
Why keys end up in the frontend
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.
Check 1: grep your build output, not your source
Your source code can look clean while the built bundle leaks. The bundle is what the browser gets, so check the bundle:
# Build, then search the output for anything key-shaped
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.
Check 2: see what your server actually serves
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.
Check 3: put a hard cap on every key
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:
- OpenAI / any LLM provider: a hard monthly spending limit, not just a soft alert.
-
Stripe: the secret key is never in client code — use the publishable key (
pk_) in the browser and keepsk_live_on the server. Restricted keys with minimal permissions beat a full secret key everywhere. - Email / SMS providers: a daily sending cap, so a stolen key cannot burn your reputation overnight.
Caps do not prevent leaks. They limit the blast radius, which is the part you can control after the fact.
Check 4: rotate anything that was ever exposed
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:
- Create a new key with the same permissions.
- Update the server-side configuration to use it.
- Delete the old key — do not just stop using it.
- Check the provider's usage logs for calls you did not make.
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 fix that actually works
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:
- Secret scanning in CI. Tools like gitleaks or GitHub's secret scanning catch a key the moment it is committed. Add one before you need it, not after.
- Separate keys per environment. A development key, a staging key, a production key. When one leaks, you rotate one, not everything.
The real lesson is not about keys
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
Top comments (0)