Blog · 7 min read

Your API keys are probably more public than you think.

By the Obra Insights team ·

AI coding tools are very good at making things work. They are less careful about where secrets end up. A common pattern: the app calls OpenAI or Stripe straight from the browser, the key sits in a VITE_ variable, and the first person to open DevTools can copy it. The bill arrives a few days later.

Here's how keys leak from vibe-coded apps, how to check yours in about ten minutes, and what to do if you find one.

Public keys vs. secret keys

Not every key in your frontend is a problem. Some are meant to be public:

  • Fine in the browser: the Supabase anon (or publishable) key, the Stripe publishable key (pk_live_/pk_test_), Firebase web config, and analytics IDs. These are only safe if your database rules are right; see our Supabase RLS guide.
  • Never in the browser: Stripe secret keys (sk_live_, rk_live_), the Supabase service_role key, OpenAI or Anthropic keys (sk-, sk-proj-, sk-ant-), AWS keys (AKIA...), email API keys like Resend (re_) or SendGrid (SG.), and webhook signing secrets (whsec_).

How keys leak

1. The public prefix

Vite apps (most Lovable and Bolt projects) expose any variable starting with VITE_ to the browser. Next.js does the same for NEXT_PUBLIC_. When an assistant hits "undefined" for a secret, the fastest fix is adding that prefix. It works, and it publishes the secret in your JavaScript bundle.

2. The committed .env file

If .env isn't in .gitignore before your first commit, it goes to GitHub with everything else. Making the repo private later doesn't help if it was ever public, and deleting the file doesn't remove it from git history.

3. Hard-coded keys

Sometimes the key is pasted right into a component, like const openai = new OpenAI({ apiKey: "sk-..." }), often because you pasted it into the chat and the assistant used it directly.

4. Logs, errors, and screenshots

Keys also show up in console.log output, error messages returned to the browser, demo videos, livestreams, and screenshots shared on X when asking for help.

Check your app in ten minutes

  1. Search the live site. Open your deployed app, open DevTools, go to Sources (Chrome) or Debugger (Firefox), and search all files (Ctrl/Cmd+Shift+F) for sk_live, sk-, service_role, AKIA, re_, and whsec_.
  2. Search the build. Run npm run build, then search the output folder: grep -rE "sk_live|sk-|service_role|AKIA|whsec_" dist/ (or .next/). To catch a service_role key, decode any JWT you find and check its role claim.
  3. Search the repo, including history. git log -p | grep -E "sk_live|sk-|service_role" is a quick check. Tools like gitleaks or trufflehog do a thorough one. On GitHub, turn on secret scanning and push protection for the repo.
  4. Check every prefixed variable. List every VITE_ or NEXT_PUBLIC_ variable in your .env and host settings. Each one should be something you'd be comfortable printing on your homepage.

If you find a leaked key

  1. Rotate it first. Create a new key in the provider's dashboard and revoke the old one. Removing it from your code doesn't help if it's already been copied, and bots scan GitHub for new keys within minutes.
  2. Check usage. Look at the provider's usage and billing pages for activity you don't recognize, and set spend limits or budget alerts where the provider offers them.
  3. Move the call to the server. Anything that needs a secret belongs in a server function: a Supabase Edge Function, a Vercel or Netlify function, or a Cloudflare Worker. The browser calls your function; your function holds the key and calls the provider.
  4. Store the secret in the right place. Put it in your host's environment settings or your Edge Function secrets, never in a prefixed variable and never in the repo.
  5. Restrict what's left. Use restricted Stripe keys with only the permissions you need, and lock Google API keys to your domain.

Keep it from happening again

  • Add .env* to .gitignore on day one and commit a .env.example with blank values instead.
  • Tell your assistant up front: "Never put secret keys in client code or in VITE_ or NEXT_PUBLIC_ variables. Use a server function." Put that line in your project rules file.
  • In Cursor, add .env to .cursorignore so it isn't sent to the AI as context.
  • Don't paste live keys into AI chats. Use placeholder values and add the real ones in your host's dashboard.

Want someone to check?

Our free app scan looks at a public URL or public repo for exposed secrets and obvious config problems, and emails you what to fix first. If something turns up, a $149 Quick Fix moves one leaky integration behind a server function, or the $99 Health Scan audits the whole app. If your deploy is also failing, start with our deploy checklist.

Want a second pair of eyes on your app?

Send us a public URL or repo. The free app scan checks for the common deploy, auth, and security problems and emails you what to fix first.

Get a free app scan