Skip to contentLockpick
How it worksPricingDocs

Read

  • BlogPlain answers to common security questions
  • GuidesStep by step fixes for common setups
  • Security checksEvery check we run, explained

Learn

  • Learn with PickTwo-minute lessons on how sites get attacked
  • Lockpick for ClaudeCheck sites from Claude and other assistants
  • GlossaryThe words we use, in plain words

Company

  • ChangelogWhat changed, newest first
  • StatusWhether scans are running right now
  • Security and trustHow we check and what we never do
Sign inCheck it
Blog

API keys in your JavaScript bundle, how they get there and what to do

By Mark KashefPublished October 8, 2026

If a secret key is in your JavaScript bundle, it is public. Your website's code runs in the visitor's browser, so the browser has to download it, and anyone can open it and read it. Replace the key first, then move the code that needs it to your server.

How does a key end up in the bundle?

Usually through a public prefix. Next.js inlines any NEXT_PUBLIC_ value into the JavaScript sent to the browser. Vite exposes VITE_ variables in client-side source code after bundling, and its docs say they should not contain sensitive information such as API keys. A key pasted into a component while testing ends up there too.

Curious what your site shows from outside? The quick check is free and needs no account.

Check it

Which keys are fine to ship?

KeyFine in the browser?Why
Supabase publishable or anon keyYesIt only reaches what your access rules allow
Stripe publishable keyYesIt can only start a checkout
Stripe secret keyNoIt can act on your whole account
OpenAI or Anthropic API keyNoAnyone can spend your credit with it
Supabase secret or service_role keyNoIt skips row level security

What to do, in order

  1. Treat a leaked key as used, because even if you remove it now, someone may already have it.
  2. Create a new key with the service that issued it and delete the old one.
  3. Move the call that needs it into a server route or function that reads the key from an environment variable or your host's secrets.
  4. Deploy, then check the live site again so you know the old bundle is gone.

Replacing the key matters more than deleting it from your code, because deleting only stops new copies. Check the service's usage and bills for anything you did not do.

How to find one

Atlas, our example app at atlas.example, is the kind of site to test. Run a quick check on your published address to see what a stranger sees, then read how we check for what it covers. An outside check reads the scripts the live site serves. It does not see your repository, so a key that only lives in your code history needs a repository scan as well.

Questions people ask

I deleted the key from my code. Am I safe?

Not yet. Anyone who already copied it can still use it, so replace the key with the service that issued it.

Is hiding the key in an environment variable enough?

Only if the variable has no public prefix and the code that reads it runs on the server. A public prefix puts the value back in the bundle.

See what your site shows from outside

A quick check reads your homepage the way a visitor would and gives you a score. No account needed.

Check your site

Related pages

  • Your OpenAI or Anthropic key is in the browser. Now what?
  • Supabase anon key vs service role key, which one can be in your frontend
  • Fix it with your AI, prompts for Lovable, Bolt, Replit, v0, Cursor and Claude Code

Sources

  1. A secret key in your website's code Lockpick docs, read on October 6, 2026
  2. Env Variables and Modes Vite docs, read on October 6, 2026
  3. How to use environment variables in Next.js Next.js docs, read on October 6, 2026

About the author

Mark Kashef, Founder of Lockpick

I'm Mark, and I build Lockpick. I write these pages, and each one is checked against its sources before it goes live. The Updated date changes only when the page itself does.

Lockpick
PricingMethodologyDocsBlogGuidesSecurity checksLearn with PickSecurity and trustLockpick for ClaudeChangelogStatusFacts for AI assistants

Lockpick is a security scanner for vibe-coded apps. It checks what your live site exposes and what a GitHub repo or AI skill would do before you install it, then gives you a fix prompt for Lovable, Bolt, Replit, Cursor or Claude Code.

Lockpick assesses public pages you are authorized to test, and public GitHub code it never runs.

© 2026 LockpickTermsPrivacyContactSign in