Leaked api key fix
Vibe Coding Rescue

I Leaked an API Key in My Vibe-Coded App: What to Rotate, In What Order

7 min read | Updated September 2026

You searched your deployed site’s source, or you got an email from GitHub, or your OpenAI bill jumped overnight — and there it is: a secret key sitting in code that anyone can read. This is the most time-sensitive problem a vibe-coded app can have, and the response is the same every time: rotate first, investigate second, fix the code third. Here is the order.

Do this in the next 15 minutes

Rotate the key. Go to the provider’s dashboard, create a new key, and revoke the old one. Do not delete the file, do not rewrite the commit, do not “make it private” — none of that un-leaks a key that has already been read. Bots scan public repositories and deployed bundles continuously; a leaked key can be found and used within minutes of being pushed.

Which keys, in which order

If several things leaked at once, rotate in the order of what they can do:

1
Anything that can spend money or send messages
OpenAI, Anthropic, Gemini, Stripe secret key, Twilio, SendGrid/Resend, AWS access keys. These are the ones that produce a surprise invoice by morning. Rotate, then set a hard spend cap on the provider while you’re there.
2
Anything that bypasses your app’s security
Supabase service_role key, Firebase admin SDK credentials, database connection strings with passwords. These read and write every row regardless of your policies. Rotate the key and the database password.
3
Anything that impersonates your users or your app
JWT signing secrets, session secrets, OAuth client secrets, webhook signing secrets. Rotating these logs everyone out — that’s fine; do it.
4
Keys that are supposed to be public — leave them
The Supabase anon key, Stripe publishable key, Firebase web config, Google Maps browser key (with HTTP referrer restrictions). These are designed to ship to the browser. Don’t waste the panic on them — but do confirm they’re actually the public variant.

Then: find out what happened

Once the old keys are dead, look at usage. Every provider has a dashboard: OpenAI and Anthropic show requests and spend by key; Supabase shows API logs; AWS has CloudTrail; Stripe shows API request logs. You’re looking for activity you didn’t generate — unusual volume, odd hours, unfamiliar IP ranges. If you find any, note the time window: that’s the period during which your data may have been read, and it matters for the next step.

If the leaked key could read user data (category 2 above) and you see unexpected access, you may have a disclosure obligation depending on where your users are. That’s a question for a lawyer, not a blog post — but the answer is easier when you have the log window in hand.

Then: stop it happening again

Get the secret out of the code

Secrets belong in environment variables on the server, read at runtime. In a Next.js app, anything without the NEXT_PUBLIC_ prefix stays server-side; in Vite, anything without VITE_. AI tools frequently pick the public prefix because it makes the call “just work” from the browser — which is exactly the leak. Move the call behind a server route or edge function and keep the key there.

Scrub the git history (after rotating)

Deleting the file doesn’t remove the old commit. If the repo is or might become public, rewrite history with git filter-repo or BFG, force-push, and ask collaborators to re-clone. This is cleanup, not protection — the key is already rotated, so this just stops the dead key showing up in scans forever.

Add a tripwire

Enable GitHub secret scanning and push protection on the repo (free for public repos, and available on private ones). Add a pre-commit hook such as gitleaks. Set spend alerts and hard caps on every paid API. Put a rate limit on any endpoint that calls a paid service, so a leaked public endpoint can’t run up your bill either — see the vibe coding security checklist for the rest of that list.

How this fits the bigger picture

A leaked key is rarely the only gap. The same “make it work” pressure that put the key in the client usually also skipped ownership checks and server-side validation. Once the fire is out, the 12-point prototype audit is the systematic pass. And if you’re not confident you found everything — or you’re not sure which keys are which — that is a reasonable moment to bring in an engineer for a day rather than guess.

FAQ

I leaked my OpenAI / Anthropic key. Will they refund the charges?
Policies vary and change; some providers have refunded first-time abuse after a leaked key was reported promptly. Rotate first, then open a support ticket with the time window. Don’t count on it — set spend caps.
The key is in a private repo. Is it still a problem?
Lower risk, but yes: collaborators, CI logs, forks and future accidental publishing all extend exposure. Rotate it and move it to environment variables anyway.
GitHub emailed me that a secret was detected. Is that real?
Usually, yes — GitHub’s secret scanning partners with providers and often triggers automatic revocation. Check the provider dashboard; if the key is already revoked, generate a new one and proceed with the rest of this list.
Can I just ask the AI to “remove all secrets”?
It can move them into environment variables, which is the right code change. It cannot rotate anything or check usage logs. Do those yourself first.

Not sure you found everything?

One-day secrets and access review: we sweep the bundle, the repo history, the env config and the provider logs, rotate what needs rotating, and leave you with tripwires in place.

Get It Checked Today →

Engineering Insights

Latest from Syntaxa Studio.

Loading latest posts