Leaked a Stripe secret key? What to do now

If your Stripe secret key ended up in your website, a public repository or a chat, treat it as compromised. These steps follow Stripe's own guidance.

First: which key leaked?

  • pk_live_… or pk_test_…: a publishable key. It's designed to be in your website. Nothing to do.
  • sk_live_…: a live secret key. It can do almost anything on your account. Act now.
  • rk_live_…: a restricted key. It can do what its permissions allow. Act now.
  • sk_test_…: a test key. No real money moves, but replace it and find out how it leaked.
  • whsec_…: a webhook signing secret. Someone could send fake events to your webhook. Replace it.

Step 1: Roll the key

Stripe's article on protecting against compromised API keys says to rotate a suspected compromised secret key as soon as possible. In the Stripe Dashboard, go to the API keys page and roll (rotate) the key. Rolling creates a new key and sets the old one to expire.

If you can't update your app immediately, you can usually choose a short expiry for the old key so your site keeps working for a few minutes while you deploy. If the key was public, keep that window as short as you can.

If you can't tell what was exposed (for example, a server or password store was breached), Stripe's guidance is to rotate all secret and restricted keys on the account.

Step 2: Put the new key in the right place

Update the key wherever your server reads it: your host's environment variables, your Edge Function secrets, your backend's configuration. Not in the front end. Then deploy, and use "View request logs" on the new key to confirm your integration is using it.

Step 3: Check the old key's request logs

Stripe keeps request logs per key, and you can still view them after a key is deleted. Look for:

  • requests from IP addresses that aren't your servers;
  • endpoints your app never calls (for example listing customers, creating refunds or payouts);
  • unusual volume or times.

Also look at your balance, recent refunds, payouts and customer list for anything you didn't do. If you see activity you can't explain, contact Stripe support.

Step 4: Find out how it leaked

Rolling the key fixes today. Finding the cause stops it happening again. The common causes:

  • The key is in the front end. Often a VITE_ or NEXT_PUBLIC_ variable, or the key pasted into a component so a payment would work.
  • A public repository. Committed in a config or .env file. Removing the file doesn't remove it from the history; the key must be rolled either way.
  • A file served by mistake. An .env file, backup or .git folder on the web server.
  • Pasted somewhere public: a forum post, a screenshot, a support chat.

Our free exposed API key checker looks for the first kind in your live site in a few seconds.

Step 5: Make the next leak smaller

Stripe's API key best practices recommend a few things that limit the damage of any future leak:

  • Use restricted keys with only the permissions each part of your system needs, instead of the full secret key everywhere.
  • Restrict keys to your servers' IP addresses where your hosting allows it.
  • Keep secret keys server-side only, in your host's secrets, and never in code or chat.

If the leaked secret was a webhook signing secret, roll it from that webhook endpoint's settings in the Dashboard and update your server.

Where AI-built apps go wrong

When you ask an AI builder to "add Stripe payments", the quickest working answer may call Stripe from the browser with the secret key. It works in the preview, so nobody notices. The safe version creates the payment on the server (an Edge Function or API route) and only sends the browser what it needs, like a Checkout URL or a client secret for one payment.

Where to keep the new key

The rule is simple: the secret key lives only where server code runs, and it's read from a secret or environment variable at that moment.

  • Supabase Edge Functions: set it as a function secret (Supabase docs) and read it inside the function.
  • Lovable: its secrets are encrypted and passed to your Edge Functions, never to the browser.
  • Next.js and similar frameworks: a server-only environment variable, without the NEXT_PUBLIC_ prefix, used only in API routes or server code.

Never put it in a VITE_ or NEXT_PUBLIC_ variable, a config file that ships to the browser, or a prompt to your AI builder.

If the key was in a public GitHub repository

Deleting the file in a new commit doesn't remove the key from the repository's history, and copies or forks may already exist. Roll the key first, as above; only then think about cleaning the history. A rolled key in old history is harmless; a live one is not.

A checklist you can copy

  • Key rolled in the Stripe Dashboard.
  • New key stored only on the server, and the app deployed with it.
  • New key's request logs show your integration using it.
  • Old key's request logs checked for unknown IP addresses, endpoints and volume.
  • Balance, refunds, payouts and customers checked for changes you didn't make.
  • Stripe support contacted about anything you can't explain.
  • Cause found and fixed (front end, repository, served file or a paste).
  • Restricted keys and IP restrictions set up where they fit.
  • Live site checked again for exposed keys.

What Securick tests

  • #1 Stripe live secret key exposed Free
  • #36 Stripe restricted key exposed Pro
  • #113 Stripe webhook signing secret exposed Free
  • #115 Stripe test secret key exposed Free
  • #11 .env file public Free
  • #12 .git folder public Free

Every finding shows where we saw the key, with the key masked.

Questions

I deleted the key from my code. Is that enough?

No. Old builds, caches and copies may still have it, and anyone who saw it can keep using it until it's rolled. Roll the key in Stripe first.

Will rolling the key break my site?

Anything still using the old key stops working once it expires. Update your server with the new key and deploy, then check the new key's request logs.

Stripe emailed me about an exposed key. What does that mean?

Stripe says it may notify you when it detects an exposed secret or restricted key, and sometimes deactivates it itself. Follow the same steps: roll, update, check the logs.

Check your live app now

Paste your app's address. The free scan runs 46 tests and shows proof for everything it finds.