Your Stripe secret key is public. Rotate it before anyone uses it.
Last reviewed November 28, 2026 against the providers' current documentation.
The short version
Rotate the key in the Stripe Dashboard now, even if you're not sure anyone saw it: Stripe's own advice is to rotate "even if you aren't sure anyone saw it." Rotating lets the old key keep working for a time you choose (up to 7 days), so you can switch your server over without breaking checkout. Then move every Stripe call that uses the secret key to your server, check for payouts, refunds and accounts you don't recognize, and give the new key only the permissions and network access it needs.
Why it matters
A secret key (sk_live_…) can make any API request on your Stripe account; a restricted key (rk_live_…) can do whatever permissions it was given. With one, someone can issue refunds, read customer details, create connected accounts and send payouts. Bots scan public code for these keys constantly. Stripe says that when it detects an exposed secret or restricted key it notifies you and may deactivate the key, but also that it "doesn't guarantee detection of all exposed or compromised keys." Publishable keys (pk_live_…) are different: they're meant to be in your frontend.
Fix it, in this order
Rotate the key
In the Stripe Dashboard, go to Developers → API keys. Click the overflow menu (⋯) next to the exposed key and choose Rotate key. In the Expiration dropdown, pick a time just long enough to update your server (Now deletes the old key at once), then click Rotate API key. Both keys work for up to 7 days. In live mode Stripe shows the new key only once, so save it straight into your host's secret store.Put the new key on your server only
Stripe recommends a secrets vault from your hosting platform, or environment variables on your backend, and never keys in source code or in config files checked into version control. Never put it in aVITE_…orNEXT_PUBLIC_…variable, which gets copied into the browser (see VITE_ variables and NEXT_PUBLIC_ variables).Move Stripe calls out of the browser
Creating payments, Checkout Sessions, refunds and customers must happen on a server: a Next.js API route, a Supabase Edge Function or your backend. The browser should only use the publishable key, for example with Stripe Checkout or Stripe Elements.Confirm the new key works, then delete the old one
Use the ⋯ menu on the new key and choose View request logs (it opens Workbench) to confirm your app is using it. Then use ⋯ → Delete key on the old one if it hasn't expired yet. Stripe says deletion is effective immediately, and you can still view request logs for the deleted key.Look for damage
Review what the old key did in Workbench logs. Stripe's checklist for a compromised key: pause or reject payouts and connected accounts you don't recognize, reverse unknown payouts, refund fraudulent charges, and rotate all your other secret and restricted keys too. Contact Stripe support if you need help reversing payouts.Use a restricted key with an access policy
Stripe recommends restricted keys (rk_live_…) for most use cases: create one per part of your app with only the permissions it needs, so a future leak can do less. Stripe also recommends an access policy on all live keys: create one under Access policies (by IP address, or by network, country and threat sources such as Tor exit nodes), then apply it from the key's ⋯ → Manage access policy. Stripe blocks requests from anywhere else and notifies you. Access policies replaced the older IP address restrictions.
Or ask your AI tool to do it
Paste this into Lovable, Bolt, Cursor, Claude Code or whichever tool built your app. Review what it changes before you deploy.
My Stripe secret key was exposed in frontend code. Move every Stripe operation that uses the secret key (creating checkout sessions, payment intents, customers, refunds) into server-side code, such as an API route or edge function. Read the key from a server-only environment variable called STRIPE_SECRET_KEY. The frontend must only use the publishable key. Do not put the secret or restricted key in any VITE_ or NEXT_PUBLIC_ variable or in any file committed to git. Also verify webhook signatures on the server with STRIPE_WEBHOOK_SECRET. Then list exactly which Stripe API resources the server code calls, so I can create a restricted key with only those permissions.
How this happens
The Stripe examples an AI tool learned from often call the API directly, and in a single-page app the simplest place to put that call is the browser. The secret key comes along with it.
Check that it's really fixed
After you deploy, run the free check. It reads your live site the way an attacker would and tells you if any secret key is still visible.
Topic check: Exposed API key checker
Find the other leaks before someone else does
The free check reads your home page and its scripts. The website security report goes through up to 30 pages and 40 JavaScript files, plus .env and .git files, security headers, cookies and CORS, domain and email records, and libraries with known vulnerabilities. Every finding comes with the fix for your host and a prompt for your AI tool.
$19 once, including 20 runs over 30 days so you can fix things and check again.

Questions
Stripe emailed me about an exposed key. Is it real?
Stripe does detect some exposed keys: it notifies you, asks you to rotate, and in some cases deactivates the key itself. Check by logging into the Dashboard directly, not through a link in the email. Stripe says it never asks you for your secret API key.
Can I see my old live secret key again?
Usually not. Stripe shows a live secret key you create one time; you can reveal only keys Stripe created for you (such as the default secret key), and it can't recover lost keys. If you've lost it, rotate or delete it and create another. In a sandbox you can always see your keys.
How long can the old key keep working?
When you rotate in the Dashboard, both keys work for up to 7 days. If you need longer, Stripe suggests creating a new key yourself, moving your app to it, then expiring the old one. For an exposed key, keep the overlap as short as you can.
Is a restricted key (rk_live) leak less serious?
It depends on its permissions: a restricted key can do exactly what it was allowed to do, which may still include refunds or customer data. Treat it the same way: rotate, check logs, and fix the code that exposed it.
Is my publishable key a problem?
No. Publishable keys are designed for webpages and apps. For test keys, see Stripe test key (sk_test) exposed.
How does your check find a Stripe key?
The free check reads your site's JavaScript and flags any sk_live_ or rk_live_ key as critical (and sk_test_/rk_test_ as high). We show only a redacted preview. The $19 report scans up to 40 of your scripts across up to 30 pages.
Sources
- Stripe: API keys (rotate, reveal, expire, access policies)
- Stripe: Best practices for managing secret API keys
- Stripe Support: Protecting against compromised API keys