API Keys Exposed in JavaScript: How to Find and Fix Them

Secret API keys in front-end JavaScript can be copied by anyone. How to tell publishable from secret keys, find leaks in your bundle and move secrets server-side.

Yrzo AI28 November 2026 2 min read

Everything in the browser is public

Your website's JavaScript is downloaded by every visitor. Anyone can open developer tools, search the files and copy what they find. If a secret API key is in there, it is not secret.

Publishable vs secret keys

Some keys are designed to be public:

  • Stripe publishable keys (pk_live_...)
  • Firebase web config and Supabase anon keys — safe only if your database rules are correct; see Firebase and Supabase misconfiguration
  • Google Maps keys restricted to your domain

Others must never reach the browser:

  • Stripe secret keys (sk_live_...)
  • AI provider keys (OpenAI, Anthropic and similar)
  • email service keys (SendGrid, Mailgun, Postmark)
  • Supabase service role keys, AWS secret keys, database passwords

What happens when a secret key leaks

Is your site exposed to this?

Run a free, non-intrusive check of what attackers can see from outside. No account needed.

  • AI and SMS keys get used to run up large bills
  • email keys get used to send phishing from your domain
  • payment keys can be used to issue refunds or read customer data
  • cloud keys can expose storage buckets and servers

How to find leaks in your site

  1. Open your live site, then developer tools → Sources, and search for key, secret, token, sk_ and Bearer.
  2. Check build-time environment variables. In many frameworks, variables with a public prefix (NEXT_PUBLIC_, VITE_, REACT_APP_) are baked into the bundle.
  3. Check source maps — if .map files are public, your original source is too.
  4. Run a free scan; Yrzo AI looks for common secret patterns in served JavaScript.

How to fix it

  1. Rotate the leaked key immediately. Removing it from the code is not enough — it is already out.
  2. Move the call server-side. The browser calls your server; your server calls the API with the secret.
  3. Restrict what remains public. Lock publishable keys to your domains and minimum permissions.
  4. Add rate limits to the server endpoints that use paid APIs. See API rate limiting.
  5. Scan in CI so secrets are caught before deployment.

Our API key security best practices covers storage, rotation and least privilege, and vibe coding security explains why AI-built apps are prone to this.

Check your site

Yrzo AI flags exposed keys, source maps and config files in every report. See plans.

Related reading: Exposed .env Files: Why They Are Dangerous and How to Check Yours · Firebase and Supabase Misconfiguration: How Apps Leak Their Whole Database · React App Security Checklist: Front-End Risks That Matter

API key exposed in JavaScriptsecret key in frontend codeleaked API keys websitehide API keys front end
Share

Check your own website in 60 seconds

Free check, no account needed. Want the full picture? Full reports start at £149, with up to 110 checks with a 14-day money-back guarantee.

Keep reading