AppInspected

Fix guides

Your Stripe test key (sk_test) is public. Here's what that means and what to fix.

Last reviewed November 6, 2026 against the providers' current documentation.

The short version

No real money is at risk from the key itself: Stripe says payments in a sandbox aren't processed by card networks, and sandbox objects can't be used in live mode. Still, rotate it and move every call that uses it to your server, because Stripe lists secret (sk_) and restricted (rk_) keys as not safe to expose, test or live. Then check two things that matter more: that your live site isn't still taking "payments" with test keys, and that your live key won't end up in the same place.

Why it matters

Stripe's docs say only publishable keys (pk_test_…, pk_live_…) are safe outside your backend. A secret key has unrestricted permissions on all Stripe APIs, so whoever copies your sk_test_… key can read and change everything in that sandbox: test customers and whatever names or emails you entered for them, products, prices, subscriptions and webhook endpoints. That's annoying rather than costly. The real risks are what it usually comes with. Stripe says you can't process live payments while your integration uses test keys, and that test cards such as 4242 4242 4242 4242 work with test keys; so if your published app uses test keys, anyone can "pay" with a test card, and if your app unlocks paid features when a payment succeeds, they get them for free. And code that ships the test secret key to the browser will ship the live one the day you switch.

Fix it, in this order

  1. Check which key it is

    pk_test_ is a publishable key and is fine in your frontend. sk_test_ (secret) and rk_test_ (restricted) are server-only keys. Search your built files for sk_test_, rk_test_ and sk_live_, or run our free exposed API key checker on the live site; if you also find sk_live_ or rk_live_, stop here and follow Stripe secret key exposed first.
  2. Rotate the test key

    In the Stripe Dashboard, open your sandbox, go to Developers → API keys, click the ⋯ menu next to the key and choose Rotate key. Pick an expiration for the old key (Now deletes it; otherwise Stripe keeps both working for up to 7 days). Stripe's best-practices page says to treat any sensitive key you find in code, including sandbox keys, as exposed and compromised. In a sandbox you can reveal your keys again later, unlike live mode.
  3. Move every secret-key call to a server

    Creating Checkout Sessions, PaymentIntents, customers, subscriptions and refunds has to happen on a server: an API route, a Supabase Edge Function or your backend, reading the key from a server-only secret such as STRIPE_SECRET_KEY. Never put it in a VITE_… or NEXT_PUBLIC_… variable; those are copied into the browser (see secrets in VITE_ variables). The browser only needs the publishable key, for Stripe.js, Elements or a redirect to Checkout.
  4. Prefer a restricted key on the server

    Stripe recommends restricted keys (rk_…) for most server code: give the key only the permissions your integration uses (for example Checkout Sessions and Customers), so a leak can do less. Stripe also suggests access policies that only accept requests from your servers' IP addresses or network.
  5. Only grant access for live payments

    In the code that unlocks a purchase (your webhook handler or success check), confirm the payment server-side and check the livemode field: Stripe sets it to true for live objects and events and false for test ones. Each webhook endpoint has its own signing secret, so verify signatures with the secret of the live endpoint.
  6. Switch to live keys when you launch

    Stripe's go-live steps: replace pk_test_ with your pk_live_ key in client code, give your server the live rk_live_ or sk_live_ key from your secrets store (not from code), and update each webhook endpoint and its signing secret. Then run the key checker again; it should find no sk_ or rk_ key in any script.

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 test secret key (sk_test_ or rk_test_) is in my frontend code. Find every place the code uses a Stripe secret or restricted key and move those calls (creating Checkout Sessions, PaymentIntents, customers, subscriptions, refunds) into server-side code, such as an API route or a Supabase Edge Function. Read the key from a server-only environment variable named STRIPE_SECRET_KEY and never from a VITE_ or NEXT_PUBLIC_ variable. The browser must only use the publishable key (pk_test_ now, pk_live_ in production) from an environment variable, so switching to live mode is a configuration change, not a code change. In the webhook handler, verify the Stripe signature with STRIPE_WEBHOOK_SECRET, and only grant paid access when the event's livemode is true in production. List every file you changed and every environment variable I must set on my host.

How this happens

Stripe's code examples sometimes include sandbox keys so they run immediately, and AI builders copy the quickest working version: a call to the Stripe API straight from the page, with the key next to it. In test mode nothing seems wrong, payments succeed with 4242, so the key stays in the frontend until launch day.

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.

Get the report, $19 See an example report

Example report header: a score out of 100, findings by severity, Download PDF and Email me this report.

Questions

Can someone charge my customers with my sk_test key?

No. Stripe says each mode has its own keys and objects in one mode aren't accessible to the other, and that card networks don't process payments in a sandbox. A test key can't reach your live customers, charges or payouts.

Is a pk_test key in my frontend a problem?

No. Publishable keys, test or live, are designed for webpages and apps. Only sk_ and rk_ keys must stay on a server.

Do I really need to rotate a test key?

Yes, it takes a minute. Stripe's best practices say to treat any sensitive key found in code, sandbox keys included, as exposed, and anyone holding it has full access to that sandbox's data and settings, including any real names or emails you used while testing.

Why does my published app still accept the 4242 test card?

Because it's still using test keys. Stripe says you can't process live payments with test keys, so nothing was actually charged. Switch the publishable key to pk_live_ and the server key to a live key, and make your fulfillment code check livemode.

Will Stripe warn me about an exposed key?

Stripe says it notifies you, and sometimes deactivates the key, when it detects an exposed secret or restricted key, but doesn't guarantee it will detect every one. Don't wait for an email.

Does the $19 report check for this?

Yes. The report's secrets section looks for Stripe secret and restricted keys (sk_live_, rk_live_, sk_test_) across up to 40 of your JavaScript files, along with the other keys our free check looks for.

Sources

Related guides