API key exposed in your JavaScript: how to find it and fix it

Treat the key as stolen. Create a new key and switch the old one off first, then move the code that uses it to a server so the new key never reaches the browser.

Updated 19 Nov 2026 · By the Phinx team

How to tell if a key is exposed

Open your live site, open the browser's developer tools, and search the loaded JavaScript for sk_live, sk-, service_role, AKIA or secret. If you can find it, so can anyone.

Common causes:

  • In Vite apps, any variable that starts with VITE_ is built into the browser code.
  • In Next.js, any variable that starts with NEXT_PUBLIC_ is sent to the browser.
  • A key pasted straight into a component while prototyping and never moved.

Fix it in this order

  1. Rotate the key. In the provider's dashboard (Stripe, OpenAI, Supabase, AWS), create a new key and revoke the old one. Removing it from your code is not enough: old builds, caches and your git history still hold it.
  2. Check for misuse. Look at the provider's usage and billing pages for activity you did not cause.
  3. Move the call to a server. Put the request in a server function or API route, read the key from a server-only environment variable, and have the browser call your route instead of the provider.
  4. Keep public keys public, and only those. Stripe publishable keys (pk_) and the Supabase anon key are meant for the browser. Secret keys never are.
  5. Re-check the live site. Search the loaded JavaScript again and confirm the new key is not there.

Have it checked and fixed

The free Phinx scan flags secret keys in public files, showing only the key type and its last four characters. If you want it fixed for you, a fix moves the key to a server setting, and you pay only when the re-scan confirms it is gone.

Questions people ask

Still stuck? Talk to a human
  • No. Earlier builds, CDN caches and your git history can still hold it. Rotating the key at the provider is the only way to make the old one useless.

See what your build needs

Paste your link for a free readiness score in about a minute. No sign-up.

Run the free scan

Rather talk to a human?

Not a bot. Not an agent pretending to be one. A real person in India reads every message and replies within 12 hours. Chai optional.

Talk to a human