Leaked API Keys in Your JavaScript: How to Check a Vibe-Coded App and Fix It

Why OpenAI, Stripe, and AWS keys end up in a vibe-coded app's public JavaScript bundle, how to check for them, and the safe order to fix a leak.

Updated 2026-10-28

Anything in the browser is public

When you open a web app, the browser downloads its HTML and JavaScript. Anyone can read those files with View Source or the browser's developer tools. If a secret key is written into that code, it is public, even if it is buried in a minified bundle.

AI coding tools often get an app working fast by calling an API straight from the page. That works in a demo, but it means the key ships to every visitor.

How keys usually leak

Most build tools copy certain environment variables into the browser bundle on purpose. In Next.js that is anything starting with NEXT_PUBLIC_; in Vite it is anything starting with VITE_. Put a secret in one of those and the build writes it into the JavaScript.

  • An OpenAI or Anthropic key used to call the model directly from a React component
  • A Stripe secret key (sk_live_) used to create a checkout from the page
  • AWS access keys used to upload files straight from the browser
  • A Supabase service_role key used to get around a permissions error
  • A GitHub, Slack, or SendGrid token pasted into a config file

Keys that are meant to be public

Not every key in the browser is a problem. A Stripe publishable key (pk_live_ or pk_test_), the Supabase anon key, and the Firebase web apiKey are designed to be in the client. They are safe only when the server side is locked down: Stripe secret calls on your server, Supabase row level security, and Firebase security rules.

Fix it in this order

Deleting the key from the code is not enough, because it is already out. Do this:

  • Rotate first: create a new key in the provider's dashboard and revoke the leaked one.
  • Check the provider's usage and billing pages for calls you did not make.
  • Move the call to the server: an API route, server action, or edge function that holds the key in a server-only environment variable (no NEXT_PUBLIC_ or VITE_ prefix).
  • Redeploy, then check the live site again to confirm the old pattern is gone.

A prompt you can paste into your coding agent

Adjust the provider name, then paste this into Cursor, Lovable, or Claude:

Find every place this app calls the OpenAI API from browser code. Move those calls into a server-side API route that reads OPENAI_API_KEY from a server-only environment variable. The browser should call our own route instead. Make sure no environment variable that holds a secret starts with NEXT_PUBLIC_ or VITE_.

Check your live app for free

Freedom Check's free scan reads your live page and up to 8 same-site scripts it loads (plus any public source maps) and looks for OpenAI, Anthropic, Stripe, AWS, GitHub, Slack, and SendGrid key patterns, private keys, Supabase service_role keys, and random-looking values assigned to names like apiKey or secret. Evidence is redacted in the report.

The free scan shows how many issues turned up and explains the most serious one with a fix prompt. The full report is $19 one time, or $29/month for unlimited.

Run a free scan →See pricing