vibe-audit.lab

guides · 2026-11-14

Stripe Secret Key in Client-Side Code: How Bad Is It, Exactly?

Published 2026-11-14 · Reviewed 2026-11-14 · By the Ingenious AI team

The short answer

It is as bad as it looks. A publishable key (pk_) in the browser is normal; a secret key (sk_live_) in shipped code lets anyone create charges and refunds, read customer records and spin up new API keys on your account. Roll the key in the Stripe dashboard, rebuild the checkout so payments run through your server, and review every refund and payout change in the exposure window.

Check your own app free: paste your code or enter your site URL on the Vibe-Code Audit homepage — the free scan checks for exposed secrets, injection flaws, XSS patterns, missing headers and exposed .env/.git paths, with a copy-paste fix for every finding. No credit card.

Why the mix-up happens in generated code

Stripe's own tutorials historically showed both keys near each other, and quick-start snippets paste the secret into whichever file is open. An AI assistant asked to 'make checkout work' will reach for the key that makes the API call succeed — and a secret key called from the browser does succeed, beautifully, in the demo. The failure is invisible until someone views source. Vibe-Code Audit's secret patterns include the Stripe sk_live/sk_test shape as a first-class detection, and its finding text names the blast radius, because 'a key was found' undersells what this particular string can do.

The tell in code review: any occurrence of sk_ outside a server-only file, any Stripe initialisation in a component with the secret, and any checkout flow with no backend endpoint at all. Legitimate browser code contains pk_ and nothing else.

What a holder of the key can actually do

Concretely: list your customers with their emails and card fingerprints, create and refund charges, cancel or alter subscriptions, read payout and balance history, and — the move that should scare you most — create new API keys, so rolling the leaked one does not evict an attacker who already minted their own. That last capability is why the recovery sequence below includes reviewing the account's key list, not just rolling the one you know about.

Restricted keys exist precisely to shrink this: a key scoped to only the operations your server performs (create PaymentIntents, read charges) turns a leak from an account takeover into a nuisance. Generated code never asks for one. You should.

The recovery sequence, in order

One: in the Stripe dashboard, review the API keys list and delete any key you do not recognise. Two: roll the exposed secret key — Stripe keeps the old one valid for a grace window you control, so deploy the new key to your server environment first if you need continuity, then expire the old one immediately after. Three: audit the window — refunds you did not issue, payout-account changes, new webhook endpoints pointing at foreign URLs (a classic persistence trick), and customer exports. Four: rebuild the flow so the secret never leaves the server: the browser gets a client_secret for one PaymentIntent from your backend, confirms with the publishable key, and that is all it ever holds.

Keeping the demo honest next time

Add two mechanical guards. A scan of every frontend build for the sk_ shape — the same pattern the scanner uses — wired to fail the build. And a repo rule: secret keys are referenced only as environment variables in server files, so a grep for process.env.STRIPE_SECRET in client directories returning a hit is itself a review blocker. AI assistants follow the shape of the repo they are given; a repo where the pattern is 'secrets live server-side, referenced by name' generates code in that shape far more often.

Worked example: Tidepool Swim Shop's checkout

Tidepool Swim Shop (fictional), doing about $8,400/month, had a checkout built by an AI tool that initialised Stripe in the browser with the live secret key to 'simplify' the integration. A scan flagged 'Exposed secret: Stripe secret key' as CRITICAL. The recovery audit found the key list clean but the webhook list held one foreign endpoint added 9 days earlier, quietly receiving order events. The owner rolled the key, deleted the endpoint, rebuilt checkout around a server-created PaymentIntent with a restricted key (PaymentIntents + Charges read only), and added a build check for sk_ in client output. Refund review for the window: two small refunds totalling $74, both traced to genuine customers — luck, not safety.

The five-step fix checklist

  1. Grep every shipped bundle and repo for sk_live_ and sk_test_; any hit outside a server-only secret store is a critical incident.
  2. In the Stripe dashboard, delete any API key you do not recognise before rolling the exposed one — attackers mint their own keys.
  3. Roll the exposed key, deploy the replacement to your server's environment only, then expire the old key.
  4. Audit the exposure window: refunds, payout details, webhook endpoints, customer exports and new subscriptions you cannot explain.
  5. Rebuild checkout so the browser only ever holds the publishable key and a per-payment client_secret, ideally with a restricted server key, and add a build-time scan for sk_ in client output.

What is Stripe secret key?

the sk_live_ credential that authenticates your server to Stripe with near-total account power: charges, refunds, subscriptions, customer data, even creating further API keys. Its sibling, the pk_live_ publishable key, is deliberately public and can only start checkouts you define.

Sources

Frequently asked questions

Is the publishable key safe to expose?

Yes — pk_live_ is designed for browsers. It can only initiate checkouts and payment flows you have defined server-side. The disaster is exclusively the sk_ secret key.

My key was in a test file with sk_test_. Still serious?

Less damaging — test keys cannot move real money — but the habit is the bug. If the test key shipped, the live key is one environment mix-up away from the same fate. Fix the pattern, not just the instance.

How do I check whether someone created extra keys or webhooks?

Dashboard → Developers → API keys for the key list; Developers → Webhooks for endpoints. Anything you do not recognise gets deleted and noted with its creation date for your audit window.

Can a restricted key really replace the full secret?

For most small apps, yes: checkout needs PaymentIntent creation and charge reads, not refunds-by-API or customer exports. Scope the key to what your server code actually calls — the Stripe dashboard shows the permission list per operation.

Related guides

Browse the full library on the guides index, run the checks in the launch audit, or compare plans on pricing.


Informational explainer, not a security guarantee. Scan your code free before every deploy.

← all guides

← Back