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
- 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.
- Check for misuse. Look at the provider's usage and billing pages for activity you did not cause.
- 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.
- Keep public keys public, and only those. Stripe publishable keys (
pk_) and the Supabaseanonkey are meant for the browser. Secret keys never are. - 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.