Guides · Updated 2026-11-20
Stripe test key (sk_test_) in my frontend: does it matter?
Short answer: Yes, but not because of money. A sk_test_ (or rk_test_) key only works in a Stripe sandbox, where card networks don't process payments, so nobody can charge real cards or pay themselves out with it. It is still a secret key: Stripe says only publishable keys (pk_) are safe to expose. Anyone who copies it from your JavaScript can read and change everything in that sandbox. The bigger problem is what it tells you: your app calls Stripe with a secret key from the browser. When you switch to live keys, the same code will ship sk_live_, which does touch real money. Fix it now: rotate the test key, move Stripe calls to a server route, and give the browser only the pk_ key.
What sk_test_ is (and isn't)
Stripe's API keys page (https://docs.stripe.com/keys) splits keys by type and by mode. Sandbox (test) keys start with pk_test_, sk_test_ and rk_test_. Live keys start with pk_live_, sk_live_ and rk_live_. Each mode has its own keys, and objects in one mode can't be used in the other.
- pk_test_ / pk_live_ (publishable): safe to expose. Made for Stripe.js, Elements and mobile apps.
- sk_test_ / sk_live_ (secret): not safe to expose. Unrestricted access to all Stripe APIs in its mode.
- rk_test_ / rk_live_ (restricted): not safe to expose. Can do whatever permissions you gave it.
In a sandbox, Stripe says card networks and payment providers don't process payments and API calls return simulated objects. So a leaked sk_test_ key can't charge a real card, refund real money or send a real payout.
What a stranger can still do with your sk_test_ key
The key has full access to your sandbox. In plain words, someone who copies it can:
- Read every test customer, payment, subscription and product. If you tested with real names or emails (yours, your team's, early testers'), those are readable.
- Create, change or delete test products, prices, customers and subscriptions, which can break your test setup and confuse your next round of testing.
- Create test objects that trigger events to your sandbox webhook endpoints, or add webhook endpoints of their own, so your test environment does things you didn't cause.
- Use your sandbox as a free playground for their own testing, under your account.
None of that costs money. But it's noise in your account and it's avoidable.
The real risk: the live key is next
A sk_test_ key in your site's JavaScript means some code in the browser talks to Stripe with a secret key. A common pattern in vibe-coded apps: the AI tool is asked to "add Stripe checkout" and writes the quickest version, which creates the Checkout Session or PaymentIntent right in the page. That needs the secret key, so the key goes into a component or an env var named VITE_STRIPE_SECRET_KEY or NEXT_PUBLIC_STRIPE_SECRET_KEY. Those prefixes mean "put this in the browser bundle".
On launch day you swap the test key for the live one, and the same code now ships sk_live_ to every visitor. A live secret key has unrestricted access to your real Stripe account. That's why our scanner flags a sk_test_ key as medium (it isn't a money risk on its own) but treats it as a warning sign. If you already went live, check for sk_live_ right away: https://leakyvibe.com/guides/is-stripe-publishable-key-safe-in-frontend
2-minute check
- Open your live (or preview) site in a private window.
- Open DevTools (F12), go to Sources (Debugger in Firefox) and use Search in all files (Ctrl+Shift+F, or Cmd+Option+F on Mac).
- Search for sk_test_ and rk_test_. Then search for sk_live_ and rk_live_.
- Search for pk_test_ and pk_live_. Those are expected and fine.
- In your project, search .env files and code for STRIPE together with VITE_ or NEXT_PUBLIC_. A secret key must never have those prefixes.
Or paste your URL in the free scan at the top of this page. It reads the HTML and JavaScript your site serves and flags Stripe secret and restricted keys: live keys as critical, test keys as medium. It doesn't flag pk_ keys.
The fix
- Rotate the test key: in the Stripe Dashboard, switch to your sandbox, open the API keys page, open the ⋯ menu on the key and choose Rotate key. Stripe says rotating revokes the key and gives you a replacement that works right away. For a leaked key, don't keep the old one alive with the grace period.
- Move every Stripe call that needs the secret key into a server route or function (for example app/api/checkout/route.ts in Next.js, or a Supabase Edge Function). It reads the key from a server-only environment variable without the VITE_ or NEXT_PUBLIC_ prefix.
- Let the browser only call your route and, if you use Stripe.js or Elements, the pk_ key.
- Consider a restricted key (rk_) with only the permissions your route needs. Stripe recommends restricted keys over secret keys for new uses.
- Redeploy, then repeat the 2-minute check on the live site. Old deployments can keep serving the old bundle with the old key, which is why rotating matters more than deleting it from the code.
- Before going live, set up the live keys the same way: only in server environment variables.
// app/api/checkout/route.ts (Next.js) - secret key stays on the server
import Stripe from "stripe";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!); // no NEXT_PUBLIC_ prefix
export async function POST() {
const session = await stripe.checkout.sessions.create({
mode: "payment",
line_items: [{ price: process.env.STRIPE_PRICE_ID!, quantity: 1 }],
success_url: "https://your-site.com/thanks",
cancel_url: "https://your-site.com/pricing",
});
return Response.json({ url: session.url });
}A prompt you can give your AI tool
My Stripe secret key (sk_test_) is in my frontend code. Find every place the browser uses a Stripe secret or restricted key, including env vars with VITE_ or NEXT_PUBLIC_ prefixes. Move all Stripe calls that need it (Checkout Sessions, PaymentIntents, customers, subscriptions, refunds) into server routes that read STRIPE_SECRET_KEY from a server-only env var. The frontend should only call those routes and, if needed, use the publishable key (pk_). Take the price from the server, not from the browser. Remove the old env vars and list the files you changed.
Sources
Official source (checked 2026-11-20): Stripe Docs, "API keys" (https://docs.stripe.com/keys): sandbox keys start with pk_test_, rk_test_ and sk_test_, live keys with pk_live_, rk_live_ and sk_live_; each mode has its own keys and objects aren't shared between modes; in a sandbox card networks and payment providers don't process payments; only publishable keys are safe to expose outside your back end; secret keys have unrestricted permissions on all Stripe APIs and restricted keys are recommended instead; rotating a key revokes it and generates a replacement that works immediately, with an optional grace period of up to 7 days.