LeakyVibe

Guides · Updated 2026-11-12

Is my Stripe publishable key safe in the frontend? pk_ vs sk_ vs restricted rk_ keys

Short answer: Yes for the publishable key (pk_live_ / pk_test_): Stripe lists it as safe to expose and made it for Stripe.js, Elements and mobile apps. It can identify your account and create tokens or PaymentMethods, but it can't create charges or read account data. No for the secret key (sk_...) and no for restricted keys (rk_...): Stripe says only publishable keys are safe outside your back end. A secret key has unrestricted access to all Stripe APIs, and a restricted key can do whatever permissions you gave it. If an sk_ or rk_ key shows up in your site's JavaScript or in a public repo, rotate it in the Stripe Dashboard right away and move all Stripe calls that need it to your server.

Does your app have this problem? Free scan, 15 sec, no sign-up

or watch it scan our demo app ▶

The three Stripe key types in one table

Stripe's API keys page (https://docs.stripe.com/keys) lists each key type and whether it is safe to expose. In plain words:

  • Publishable key, starts with pk_live_ or pk_test_. Safe to expose: yes. Used by Stripe.js, Elements and the mobile SDKs. It can identify your account and create tokens or PaymentMethods from payment details, but it can't perform sensitive operations such as creating charges or reading account data.
  • Secret key, starts with sk_live_ or sk_test_. Safe to expose: no. It has unrestricted permissions on all Stripe APIs. Stripe now recommends restricted keys instead of secret keys for new uses.
  • Restricted key (RAK), starts with rk_live_ or rk_test_. Safe to expose: no. It only has the permissions you choose, which limits the damage if it leaks, but it still belongs on your server.
  • Organization key, starts with sk_org_. Safe to expose: no. Like a secret or restricted key, but for several Stripe accounts at once.

The webhook signing secret (whsec_...) is not an API key, but it is also a secret: your webhook route uses it to check that an event really came from Stripe. Keep it on the server too.

_test_ keys only touch sandbox data, so a leaked sk_test_ key can't move real money. It can still read and change your test data, so rotate it as well, and treat it as a sign the live key may be handled the same way.

Why vibe-coded apps leak sk_ keys

When you ask an AI tool to "add Stripe checkout", the quickest code to write calls the Stripe API straight from the page. That needs the secret key, so the tool puts it where the page can read it: pasted into a component, or in an environment variable that starts with VITE_ or NEXT_PUBLIC_. Those prefixes mean "include this in the browser bundle", so the key ends up in the JavaScript every visitor downloads. More on that: https://leakyvibe.com/guides/is-my-vercel-app-leaking-environment-variables

Another common route is a key committed to a repo that later becomes public. Stripe's own advice is to never put keys in source code or config files checked into version control.

The right shape is simple: the browser only ever gets the pk_ key. Anything that creates a Checkout Session, a PaymentIntent, a refund or a subscription change runs in a server route or function that reads the secret or restricted key from a server-only environment variable.

5-minute check: which Stripe key does my live site ship?

  1. Open your live site in a private window.
  2. Open DevTools (F12 or right-click > Inspect), go to the Sources tab (Debugger in Firefox) and use "Search in all files" (Ctrl+Shift+F, or Cmd+Option+F on Mac).
  3. Search for sk_live_, then rk_live_, then sk_test_ and rk_test_. Any match is a problem.
  4. Search for pk_live_ and pk_test_. A match here is normal and expected.
  5. Also search your repo (including git history if it was ever public) for sk_ and rk_ strings.

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 sk_ and rk_ keys (live keys as critical, test keys as medium). It does not flag pk_ keys, because those are meant to be public.

Found an sk_ or rk_ key in public? Do this, in this order

  1. Rotate the key on the API keys page of the Stripe Dashboard (the ⋯ menu on the key, then Rotate key). Stripe says rotating revokes the key and gives you a replacement that works immediately. For a leaked key choose expiration Now, so the old one stops working at once; the 7-day grace option is meant for planned rotations, not leaks.
  2. Put the new key only in your server's environment variables (on Vercel: a variable without the NEXT_PUBLIC_ or VITE_ prefix, read only in server code), then redeploy.
  3. Move every Stripe call that used the secret key from the browser into a server route.
  4. Look at your Stripe Dashboard for payments, refunds, customers or payouts you don't recognize.
  5. If the key was in a git repo, remove it from history too. Rotating first matters more: the old key stays copied wherever someone saved it.

Full checklist for any leaked key, not only Stripe: https://leakyvibe.com/guides/leaked-api-key-what-to-do

Use a restricted key instead of the secret key

Stripe recommends restricted keys for most use cases. Give each part of your app its own rk_ key with only what it needs, for example a key that can only create Checkout Sessions. If that key ever leaks, the damage is limited to those permissions. Stripe also lets you attach access policies to keys so they only work from servers you name.

A restricted key is still not safe in the browser. Smaller damage is not zero damage.

A prompt you can give your AI tool

Audit this app's Stripe integration. The browser may only use the Stripe publishable key (pk_). Find every place a secret (sk_) or restricted (rk_) key, or the webhook secret (whsec_), is used or could reach client code, including env vars prefixed NEXT_PUBLIC_ or VITE_. Move those calls into server routes that read the key from a server-only env var, and make sure checkout, refunds and plan changes are only triggered from the server. Don't print any key values. List the files you changed.

Sources

Official sources (checked 2026-11-12): Stripe, "API keys" (https://docs.stripe.com/keys): key types table with "Safe to expose", key prefixes, Protect your keys, Rotate an API key (7-day grace, expiration Now), restricted keys and access policies. Next.js environment variables (https://nextjs.org/docs/app/guides/environment-variables) and Vite env and mode (https://vite.dev/guide/env-and-mode) for which variables are bundled for the browser.

Check your app for this now

Free scan · about 15 seconds · no sign-up

Passive, read-only checks. Only scan apps you own or have permission to test.