My Stripe secret key is in my frontend code. Now what?

Your account's sk_live_ key belongs on a server. In your JavaScript bundle, anyone can copy it and use it to make charges, issue refunds and read customer data. Fix it in this order.

How to fix it

  1. In the Stripe Dashboard, open Developers → API keys, click the ... menu next to the key and choose Rotate key. Do this before anything else. Some Stripe pages still call this rolling a key. In the dialog, set Expiration to Now unless that would stop payments you can't pause. If it would, pick the shortest time that covers your redeploy, because the old key keeps working until then.
  2. Copy the new key and save it, because Stripe won't show it again.
  3. Store the new key only as a server-side environment variable (for example in Vercel → Settings → Environment Variables), with a name that does not start with NEXT_PUBLIC_ or VITE_.
  4. Move every call that uses the key into a server route (a Next.js route handler, a Supabase Edge Function or a serverless function) and have the browser call that route. Keep only the pk_live_ key in the browser, for Stripe.js and Elements.
  5. Redeploy. Choose View request logs from the new key's ... menu to confirm your app is using it. If the old key hasn't expired yet, expire it now from its ... menu. Stripe labels this Expire key or Delete key.
  6. Check for damage in Workbench: review the old key's recent requests for anything your app doesn't do. Its logs stay there after the key is deleted. Refund fraudulent charges. If you see payouts, bank accounts or connected accounts you don't recognize, stop them in the Dashboard, and contact Stripe support if you need help reversing a payout. Rotate any other secret or restricted keys that could have been exposed the same way.
  7. Scan again to confirm the key is gone. If the scan finds the new key, it was exposed the same way, so go back to step 1.

Common questions

What can someone do with my secret key?

Stripe lists creating fraudulent charges or subscriptions, issuing refunds (including to themselves) and reading customer data. On a Connect platform they can also change payout destinations and create payouts.

Is my pk_live_ key a problem too?

No. Publishable keys are made for the browser. One can create tokens from payment details, but it can't create charges or read account data, so the scan reports it as a pass.

The scan found an rk_live_ key. Is that less serious?

It can only do what its permissions allow, but it still doesn't belong in a browser. Follow the same steps. Stripe recommends restricted keys over secret keys for server code, so use one for the replacement if you can.

Why is my grade an F?

Any leaked key gives the scan an F until it's gone, because anyone can use a key they can read.

Fixed it? Scan again to confirm.

Scan your app for leaks