PatchPaste · Guides
Last updated 31 October 2026
Is my Stripe secret key exposed in my app?
Scan your live app free. It searches the JavaScript your site sends to every visitor for Stripe live secret and restricted keys (sk_live_, rk_live_), plus OpenAI, Anthropic, AWS, GitHub and Supabase admin keys. No login, no code access.
pk_live_ or pk_test_) belongs in your frontend. A secret key (sk_live_) or a restricted key (rk_live_) in the browser means anyone who opens DevTools can use your Stripe account. Rotate it in the Stripe Dashboard first, then move the code that needs it to a server.AI builders like Lovable, Bolt and Cursor sometimes call Stripe straight from the browser to get checkout working quickly. It works, and it ships the secret key to every visitor.
Which Stripe keys are safe to show?
From Stripe's API keys documentation:
| Key | Starts with | Safe in the browser? | What it can do |
|---|---|---|---|
| Publishable | pk_live_ / pk_test_ | Yes | Used by Stripe.js and Elements. It can create tokens or PaymentMethods, but can't create charges or read account data. |
| Restricted | rk_live_ / rk_test_ | No | Whatever permissions you gave it. Stripe still says to protect it. |
| Secret | sk_live_ / sk_test_ | No | Full access to every Stripe API on your account. |
| Webhook signing secret | whsec_ | No | Not an API key, but your server uses it to prove a webhook came from Stripe. |
Stripe's own words: “Only publishable keys are safe to expose outside your application's backend.”
How a secret key ends up in the frontend
- A client-side env variable. Anything named
VITE_(Lovable, Bolt and other Vite apps) orNEXT_PUBLIC_(Next.js) is built into the JavaScript the browser downloads.VITE_STRIPE_SECRET_KEYis a public key, whatever the name says. More on VITE_ variables → - A browser call to the Stripe API. If your app creates a Checkout Session or a PaymentIntent from React code, it needs the secret key in the browser to do it.
- A pasted key. You gave the AI your key in chat and it put it straight into a file.
Check your live app in 2 minutes
- Open your published site in a private window.
- Open DevTools → Sources (or Network, filtered to JS) and search all files for:
sk_live_andrk_live_(live keys: fix now)sk_test_andrk_test_(sandbox keys: less urgent, still fix)whsec_(webhook signing secret)
- A
pk_live_orpk_test_result is fine. That one is meant to be there.
Check the live site, not just your code. The browser gets what was built and deployed, which isn't always what's in your editor.
Found one? Fix it in this order
- Rotate the key in Stripe first. Go to the API keys page in the Dashboard, open the key's ⋯ menu and choose Rotate key. Stripe's advice is to rotate an exposed key straight away, even if you aren't sure anyone saw it.
- The trade-off: Stripe lets the old key keep working for up to 7 days so you can switch without downtime. For a key that was public on your live site, picking Now is safer. Checkout may break for a few minutes until step 3 is done.
- Move the Stripe call to a server. Save the new key as a server-only secret: Supabase Edge Function secrets (or Lovable's Secrets), or a Next.js server route with a variable that has no
NEXT_PUBLIC_prefix. Your app calls your function, and your function calls Stripe. How to store a key in Edge Function secrets → - Delete the old variable and redeploy. Remove
VITE_STRIPE_SECRET_KEY(or similar) from your env settings and code, then publish again. - Search the live JavaScript again. Repeat the 2-minute check. Only
pk_should come back. - Look at what the key did. In the Dashboard, open the old key's ⋯ menu and choose View request logs. Look for requests you didn't make.
Deleting the key from your code is not enough on its own. Old builds and your git history can still hold it, so rotate it every time.
While you're in there
- Use a restricted key on the server. Stripe now recommends restricted keys (
rk_) over secret keys for most uses, with only the permissions your code needs. If one leaks, it can do less. - Set the price on the server. Create the Checkout Session in your function with your own Price ID. Don't trust an amount sent from the browser.
- Unlock paid features from a verified webhook, not the success page. Anyone can open a success URL without paying. How to verify a Stripe webhook in a Supabase Edge Function →
A prompt to paste into Lovable, Bolt or Cursor
Move every Stripe API call that uses a secret or restricted key out of the frontend and into a Supabase Edge Function (or a server route). Read the key with Deno.env.get('STRIPE_SECRET_KEY') from Edge Function secrets. Do not use any VITE_ or NEXT_PUBLIC_ variable for it. The frontend may only use the publishable pk_ key with Stripe.js. Create Checkout Sessions on the server using our Price IDs, not amounts from the browser. Remove the old frontend variable. Then list every file you changed.After the AI makes the change, check the result yourself with the 2-minute search above. Don't take its word for it.
Before launch, run the full Lovable/Bolt pre-launch checklist. Also see is my Lovable app secure?
Stripe key FAQ
Is the Stripe publishable key safe in my frontend?
Yes. Stripe says you can include it in front-end code. It can't create charges or read your account data.
Is a sk_test_ key in the browser a problem?
It only works in a sandbox, so no real money moves. Stripe still says to audit for sandbox keys, so rotate it and move it to the server too.
Will Stripe tell me if my key leaks?
Sometimes. Stripe says that if it detects an exposed secret or restricted key, it notifies you and asks you to rotate it, and in some cases deactivates it. It also says it doesn't guarantee to catch every exposed key.
Is a restricted key safe to put in the browser?
No. Restricted keys limit the damage, but Stripe lists them as not safe to expose.
Does PatchPaste find Stripe keys?
The free scan searches the JavaScript your live site sends to visitors for Stripe live secret keys (sk_live_) and live restricted keys (rk_live_), and shows any it finds masked. It can't see your server code, Edge Functions or webhook handler, and it can't see pages behind a login. Search for sk_test_, rk_test_ and whsec_ by hand using the steps above.
Check your app for free
Paste your live URL for a free A to F report with every problem in plain English. Fix prompts for that report are a one-off £9 (or £29 for 10 reports). Scans are free to rerun, so you can check again after you rotate the key and redeploy.
Want to see one first? View a sample report.
Sources (checked 31 Oct 2026): Stripe, API keys (key types, “only publishable keys are safe to expose”, rotation, 7-day grace period, request logs, restricted keys recommended); Stripe, Best practices for managing secret API keys (rotate exposed keys immediately, audit for sandbox keys, Stripe's exposed-key notification and no guarantee of detection); Stripe, Webhooks (Stripe-Signature header and whsec_ signing secret).