Stripe secret key (sk_live_, sk_test_, or rk_) is in the front-end code
A Stripe sk_ or rk_ key shipped in the browser bundle? Only publishable keys belong there. Roll the secret and keep the new one on the server.
Reviewed October 15, 2026
What it means in plain English
Stripe's publishable key (pk_) is safe in the browser. A secret key (sk_live_ or sk_test_) and a restricted key (rk_live_ or rk_test_) are not. Stripe says only publishable keys are safe to expose, and that you should not put other keys in your application's code. Someone who loads the site can copy a leaked key and use the Stripe API with it.
Likely causes
- The AI put the secret key in a
VITE_orNEXT_PUBLIC_variable so the browser could "call Stripe". - A test key was left in the client, then the same pattern was copied for the live key.
- The key is hardcoded in a component instead of a server environment variable.
How to fix it, step by step
- Search the built site's JavaScript for
sk_live_,sk_test_,rk_live_, andrk_test_. Apk_key can stay. - Delete the secret from front-end code. Stripe's key guide says not to put keys in application code. Put the key in the host's secrets vault, or in an environment variable that is not exposed to the browser, and call Stripe from a server route.
- If the key was exposed, open the API keys page in the Stripe Dashboard and rotate or delete it, then create a replacement. Stripe says a compromised secret or restricted key should be revoked, and that code using an expired key can no longer make API calls, so update the server before you expire the old one.
- Prefer a restricted key for the server. Stripe recommends restricted keys over an unrestricted secret key because you can limit what the key is allowed to do.
How to check it worked
- Search the deployed JavaScript again. The
sk_andrk_values are gone. - A server route can still create a Checkout Session or PaymentIntent. The browser only has the publishable key.
Sources
Related fixes
More Stripe fixes
More Secret keys in the browser fixes
Keep going on your own.
The guides stay free. A deep leak report is $15. Fix packs are $24, or $49 for all three. There is no done-for-you repair.