Stripe publishable vs secret key: which one can go in your Lovable or Vite frontend
Updated 29 November 2026
Vibe-coded apps often put a Stripe key in an environment variable and call Stripe from the browser. That is fine only if the key is a publishable key, which starts with pk_live_ or pk_test_. A secret key (sk_live_, sk_test_) or a restricted key (rk_live_, rk_test_) in the frontend is already a leak: anyone who loads the page can copy it. Stripe's docs say the publishable key is safe to include in front-end code, and that secret and restricted keys are not. This guide is the Stripe-specific version of that check.
Check your own app for this, free.
Paste your live URL. ShipCheck looks for leaked API keys in your page and JavaScript, exposed files like /.env and /.git, missing security headers, SSL certificate problems, domain expiry (custom domains only) and what Google sees without running JavaScript. You'll see your score without signing up.
Short answer
Only the publishable key belongs in the frontend. Use it with Stripe.js, Elements or a mobile SDK. It can identify your account and create tokens or PaymentMethods from card details, but it cannot create charges or read account data. Secret keys have unrestricted access to the Stripe API; restricted keys have only the permissions you granted, but they are still secrets. If you find sk_ or rk_ in the live JavaScript, rotate that key first in the Stripe Dashboard, then move every secret-key call into a server function. Type just the first few characters into the is this key safe? tool (nothing leaves your browser) if you are unsure. A key that starts with sk- (a hyphen, not an underscore) is not a Stripe key; see OpenAI keys in the frontend or Anthropic keys in the frontend. For the same check across other providers, see how to check for leaked API keys.
The three prefixes, at a glance
| Prefix | What Stripe calls it | Safe in the frontend? |
|---|---|---|
pk_live_, pk_test_ | Publishable key | Yes. Built for Stripe.js, Elements and mobile SDKs. |
sk_live_, sk_test_ | Secret key | No. Unrestricted access to the Stripe API. Stripe recommends restricted keys for new server-side use. |
rk_live_, rk_test_ | Restricted key (RAK) | No. Permissions are limited, but it is still a secret. Keep it on the server. |
Live-mode keys start with _live_; sandbox (test) keys start with _test_. A test secret in the frontend cannot move real money, but it exposes test customer data and usually means the live secret will be added the same way. Organisation keys (sk_org_…) are also secrets and must stay on the server. Official reference: Stripe API keys and restricted API keys.
Webhook signing secrets (whsec_…) are not API keys. They belong only on the server that receives Stripe webhooks. You will find each one under the webhook endpoint in the Dashboard, not on the API keys page. See Stripe webhooks.
How to check the live app
Check the deployed URL, not only the editor preview.
- Search the JavaScript. Open the live site, press F12, go to Sources, and search all files (Ctrl+Shift+F, or Cmd+Option+F on a Mac) for
sk_live_,sk_test_,rk_live_,rk_test_andwhsec_. Apk_live_orpk_test_match is expected. Click the checkout or payments feature first, because some chunks only load then. - Watch the Network tab. Start a payment. If the browser sends a request straight to
api.stripe.comwith a secret or restricted key (for example in anAuthorizationheader, or as the username in HTTP basic auth), that secret is in the frontend, even if the text search missed it. Requests tojs.stripe.comthat use only a publishable key are normal. - Or grep the scripts linked from the page:
URL=https://your-app.com for js in $(curl -s "$URL" \ | grep -oE 'src="[^"]+\.js[^"]*"' | cut -d'"' -f2); do case "$js" in http*) u="$js";; /*) u="$URL$js";; *) u="$URL/$js";; esac curl -s "$u" | grep -oE 'sk_live_[0-9a-zA-Z]{8,}|sk_test_[0-9a-zA-Z]{8,}|rk_live_[0-9a-zA-Z]{8,}|rk_test_[0-9a-zA-Z]{8,}|whsec_[0-9a-zA-Z]{8,}' \ | cut -c1-12 | sort -u doneThis prints only the start of a match, so you are not pasting a full key into your terminal history. A clean result is not proof: it only covers scripts linked from the HTML, not code that loads later.
Not sure what you found? Type just the first few characters into the is this key safe? tool. Do not paste the whole key. The checker also tells publishable keys from secret ones, and Stripe sk_live_ from an OpenAI sk- key.
Why this happens in vibe-coded apps
A typical prompt is “add Stripe checkout” plus a key in an environment variable. Frontend build tools then bake any public-prefixed variable into the JavaScript:
- Vite (most Lovable and Bolt apps): variables starting with
VITE_are exposed in the client bundle.VITE_STRIPE_SECRET_KEYorVITE_STRIPE_API_KEYis a leak if the value is ansk_orrk_key.VITE_STRIPE_PUBLISHABLE_KEYis the usual, intended pattern for apk_key. Vite's docs sayVITE_*variables should not contain sensitive information such as API keys. See Vite: Env Variables and Modes. - Next.js (v0, many Cursor apps): variables starting with
NEXT_PUBLIC_are inlined into the client bundle at build time. A variable namedSTRIPE_SECRET_KEY, without that prefix, stays on the server. See Next.js environment variables.
The fix is the same on every platform: the browser uses only the publishable key (for Stripe.js or to start Checkout). Creating a Checkout Session, charging, refunding or reading customers happens in a server function that holds the secret or restricted key.
If a secret or restricted key already leaked, do this in order
Stripe's advice is to rotate the key immediately, even if you are not sure anyone saw it. Treat any exposure as a potential compromise. A leaked secret key can be used to make unauthorised charges, read customer data or disrupt your integration. See best practices for managing secret API keys.
- Rotate the exposed key in the Stripe Dashboard. On the API keys page, open the overflow menu (⋯) for the key, choose Rotate key, and set Expiration to Now so the old key is deleted. (A scheduled expiry of up to 7 days is for avoiding downtime when you already control both keys; it is the wrong choice while the old key is in a public bundle.) Copy the new key once and store it only as a server-side secret. In live mode you cannot reveal it again. Official steps: Rotate an API key in the Dashboard.
- Check for misuse. Open View request logs on the key (it opens Workbench), and review Payments, Refunds, Payouts and payout bank details for anything you did not do. Stripe says that if it detects an exposed secret or restricted key, it notifies you and may deactivate the key, but it does not guarantee it will catch every leak.
- Move every secret-key call to the server, then put the new key there only. In Lovable or Bolt, a Supabase Edge Function (Edge Functions → Secrets, or
supabase secrets set STRIPE_SECRET_KEY=…) is the usual place. In Next.js, use a Route Handler or Server Action and readprocess.env.STRIPE_SECRET_KEY, without aNEXT_PUBLIC_prefix. Remove the secret from anyVITE_orNEXT_PUBLIC_variable. Redeploy, then confirm the old key fails:curl -s -o /dev/null -w "%{http_code}\n" \ https://api.stripe.com/v1/balance \ -u OLD_SK_OR_RK_KEY:A rotated or expired key should return 401. Do not paste a live secret into a shared log.
If other secrets were in the same frontend or the same host incident, rotate those too, in priority order: which keys to rotate, and in what order. Stripe suggests using a restricted key with only the permissions you need, instead of a full secret key, for the replacement.
What ShipCheck checks (and what it doesn't)
The free scan fetches the raw HTML of your live URL and the same-origin JavaScript files linked from that HTML (and public source maps from those files, when they are available). It does not run JavaScript or click around the app. It flags a Stripe live secret key (sk_live_) or live restricted key (rk_live_) as a critical finding, a webhook signing secret (whsec_) as a high finding, and a test secret key (sk_test_) or test restricted key (rk_test_) as a medium finding. It does not flag publishable keys (pk_live_ or pk_test_), because those are meant to be public. It does not currently flag organisation keys (sk_org_), so also use the DevTools and Network checks above. The scan does not call Stripe with the key and does not rotate it for you. It does not probe Storage buckets, and it does not detect Next.js versions. The Supabase table-read test needs a free account that has verified it owns the app; the anonymous scan does not query tables. Paid plans re-scan weekly on Solo ($12/mo) or daily on Builder ($29/mo). Separately, paid plans also check once a day that the app URL returns a status below 400 (a 15 second timeout, with an email after two failed checks). That daily check is not a secrets test.
FAQ
Is a Stripe publishable key (pk_live_ or pk_test_) safe in my Lovable or Vite app?
Yes. Stripe's docs say the publishable key is safe to include in front-end code. It works with Stripe.js, Elements and mobile SDKs. It cannot create charges or read account data. Keep secret and restricted keys on the server.
Is sk_test_ okay in the frontend while I am still testing?
No. A test secret cannot move live money, but it can read and change your test customers and charges, and it usually means the live secret will be added the same way. ShipCheck flags a test secret in the frontend as a medium issue. Use only pk_test_ in the browser.
What is a restricted key (rk_), and can I put it in the frontend?
No. A restricted key has only the permissions you grant, which limits the damage if it leaks, but Stripe still classifies it as not safe to expose. Keep it on the server. Stripe recommends restricted keys instead of unrestricted secret keys for new server-side use.
I found a key starting with sk- (a hyphen), not sk_live_. Is that Stripe?
Usually not. Stripe secret keys use an underscore (sk_live_ or sk_test_). A key that starts with sk- or sk-proj- is typically an OpenAI or other AI provider secret. The key prefix checker can tell them apart. See the OpenAI frontend guide.
Does ShipCheck flag my Stripe publishable key?
No. The free scan flags sk_live_ and rk_live_ as critical, webhook signing secrets (whsec_) as high, and sk_test_ and rk_test_ as medium. It does not flag pk_live_ or pk_test_. It does not currently flag organisation keys (sk_org_), and it does not run JavaScript, so also search in DevTools if a payments feature loads code later.
Run the same checks on your app.
A free scan takes under a minute. No card, and no sign-up to see your score and the list of issues.