← Blog

How to find the API keys your vibe-coded app is leaking

A secret embedded in your frontend can be read by anyone who opens your site. That can expose data or let someone spend money through your account. Start by identifying what kind of key you have: some are intentionally public. If a secret has leaked, remove the exposure and replace or revoke it through the provider. Moving the same key to the server does not invalidate copies that are already out there.

Public by design vs. secret by necessity

Some keys are meant to ship to the browser. Supabase’s publishable key (sb_publishable_...) and legacy anon key identify the application; access to data still depends on permissions and row-level security. Its secret key (sb_secret_...) and legacy service_role key have elevated access and belong on the backend. See Supabase’s key reference.

Other providers have their own rules. Check the provider’s key type and permissions before treating a search match as a leak. A public key is not proof that the rest of your access controls are safe.

The bug is simple: a secret key ends up somewhere the browser can read it.

The four ways they leak

  1. The NEXT_PUBLIC_ / VITE_ / PUBLIC_ prefix. Frontend frameworks inline any env var with the public prefix straight into the browser bundle. Put a secret behind NEXT_PUBLIC_STRIPE_SECRET and it’s public — the prefix is a promise to ship it.
  2. A secret value passed to the frontend. A hardcoded value imported into client code, a secret included in page props, or an API response can expose it. This does not mean every server environment variable is automatically bundled: Next.js keeps non-public environment variables on the server by default. Inspect the actual output and responses.
  3. Hardcoded while iterating. “Just paste the key in for now” during a fast build, never moved out.
  4. Committed to git. A real .env checked in once stays in the git history forever, even after you delete the file — anyone who ever had repo access can still read it.

Check yours in two minutes

  • Read your own bundle. Open your live site, View Source, and search the page and its JavaScript for sk_, secret, service_role, password, Bearer. Or open DevTools → Sources and search across files. If a secret is in there, so is everyone else’s copy.
  • Grep the repo — and the history. git grep -iE "secret|sk_live|service_role|password" finds current ones; git log -p | grep -iE "sk_live|service_role" catches anything committed and later removed.
  • Watch the Network tab. Load the app with DevTools open and look at request payloads and headers. A secret riding along in a request the browser makes is a secret the browser knows.

What to do when you find one

  1. Rotate it first. Assume it’s compromised — generate a new key in the provider’s dashboard and revoke the old one. Moving it somewhere safer without rotating leaves the leaked value live.
  2. Move it server-side. The new secret lives only in a server environment variable, used in API routes, server functions or edge functions — never imported into client code.
  3. If it was in git, rotation is the fix. Rewriting history is good hygiene, but the key is already out; rotating is what actually closes it.
  4. Re-check after deploying. Rebuild, reload, and grep the bundle again to confirm it’s gone for real.

Get a second read of the code

If you are unsure whether a key belongs in the browser, start with the free self-check. It helps you identify questions to investigate; it does not inspect your code or prove that the app is secure.

For a code review, see the audit scope and price. The review looks at how secrets are used, who can reach server endpoints, and how database access is restricted. You receive findings and suggested fixes. It does not automatically change your app or replace incident response if a key is already being abused.

Prepare the repository, the framework and backend you use, and the file or feature that concerns you. Read-only repository access is the starting point; do not send API keys, passwords or customer data in a message. If your setup is unusual, ask about scope before ordering.

Built with Lovable? The Lovable audit covers the generated frontend and backend access rules. The Next.js and Supabase pages explain the checks for those stacks.