Stripe secret key (sk_live) in your JavaScript bundle? Rotate it, check your logs, move it server-side
· PlugLeak
A Stripe secret (sk_live_ or sk_test_) or restricted key (rk_live_) in VITE_ or NEXT_PUBLIC_ is in the JavaScript visitors download. How to find it, rotate it, and create Checkout Sessions on the server.
A Stripe secret or restricted key in frontend code is already public. Anyone who loads the site can save the JavaScript and read it. Secret keys have to stay in your server environment. If an unauthorized party obtains one, they can make unauthorized charges, access customer data, or disrupt your integration (Best practices for managing secret API keys). The same leak shows up in apps built with Cursor, Claude Code, Bolt, and v0 when the key has a public env prefix or is read from a client component.
Publishable, secret, and restricted keys
Stripe documents three key types on the API keys page. Only the publishable key is safe outside the back end. You are responsible for protecting the others, including restricted keys.
pk_is the publishable key. It is safe in front-end code and in Stripe.js. It can identify your account and create tokens or PaymentMethods. It cannot create charges or read account data.sk_is the secret key. It is not safe to expose. It has unrestricted permissions on all Stripe APIs. Stripe does not recommend secret keys for new use cases, and recommends migrating existing use to restricted keys.rk_is a restricted key. It is not safe to expose either. You choose its permissions. Stripe recommends restricted keys so a leaked key can do less.
Sandbox keys start with pk_test_, rk_test_, and sk_test_. Live keys start with pk_live_, rk_live_, and sk_live_. Each mode has its own keys. An object in sandbox mode is not available to live mode, and in a sandbox, card networks and payment providers do not process payments. Organization keys (sk_org_) are secret too. A sandbox secret is still a secret: Stripe says to audit sandbox keys, and if you find a sensitive key, assume it has been exposed and compromised (best practices). Rotate sk_test_ and rk_test_ the same way you rotate a live key.
Why the secret ends up in the bundle
Vite exposes names that start with VITE_ in client source after bundling. To avoid leaking env variables to the client, avoid that prefix. In the docs, import.meta.env.VITE_SOME_KEY is "123" and import.meta.env.DB_PASSWORD is undefined. VITE_* values should not contain API keys, because they are bundled into your source at build time. For production, Vite says to consider a backend server or a serverless or edge function (Env variables and modes). VITE_STRIPE_SECRET_KEY is the name Stripe calls out: that value is visible to visitors (Protecting against compromised API keys).
Next.js uses NEXT_PUBLIC_. Names without that prefix stay in the Node.js environment and are not accessible to the browser. The prefix inlines the value at build time, replacing process.env.NEXT_PUBLIC_… with a hard-coded string in the JavaScript sent to the browser. After next build, those variables stay at the value from the build (Environment variables). NEXT_PUBLIC_STRIPE_SECRET_KEY ships. STRIPE_SECRET_KEY does not, unless client code reads it. By default, environment variables are only available on the server, and Next.js exposes a variable to the client when the name starts with NEXT_PUBLIC_ (Data security).
A second path is the call itself sitting in a client component. Client Components must not access privileged data or server-only modules. They follow the same security assumptions as code running in the browser. Secret keys belong in environment variables, and only the data access layer should read process.env (Data security). Stripe says not to embed secret or restricted keys in client-side applications (Authentication). Checkout Session creation, PaymentIntents, and refunds authenticate with that key, so those calls belong on the server. Stripe also warns that a reference to a secret in Next.js page code may appear in the initial HTML (Protecting against compromised API keys).
Which names the bundler inlines is the NEXT_PUBLIC_ and VITE_ guide. On Bolt, which values can stay in .env and which belong in Secrets is the Bolt environment variables guide. An OpenAI key shipped the same way is the OpenAI frontend guide.
Advance Intelligence's November 18, 2026 story describes an X post from that month. The post shared a Reddit author's account of a booking app built with Cursor and Claude. In that account, a live Stripe secret key was in files the site sends to every visitor, because the variable name started with VITE_. Advance Intelligence says the screenshots are that author's account, not a verified incident report.
Search the live site
Open the deployed site. In DevTools, search Sources across the loaded files, or open a script in Network and search the response. Also use the browser's view-source on the HTML. Stripe says a bundled secret can be in the JavaScript or in the initial HTML. Look for:
sk_live_,rk_live_,sk_test_, andrk_test_. Apk_live_orpk_test_key can be there on purpose.VITE_STRIPE_SECRET_KEY,NEXT_PUBLIC_STRIPE_SECRET_KEY, and any other public prefix on a secret or restricted key.sk_org_, if the app uses an organization key.
Check lazy-loaded chunks, not only the first file. If a script names a source map (sourceMappingURL), open that .map URL and search it too. Read the line before you treat a placeholder as a live key, and do not paste a match into a chat.
Then run the free PlugLeak scan on the same URL. It is a passive GET of the page and same-site JavaScript, and it stops at 25 files or 12 MB. It checks /.env, /.git/config, security headers, and TLS. It detects Stripe, OpenAI, Anthropic, and AWS keys, GitHub tokens, PEM private keys, sb_secret_ keys, and service_role JWTs. The Stripe patterns it matches are sk_live_, rk_live_, and sk_test_. Search rk_test_ and sk_org_ yourself. It does not download source maps. It does not test Row Level Security or grants, query a database, log in, or crawl.
The scan is free, with no signup. Run it at https://plugleak.com/?utm_source=seo&utm_medium=article&utm_campaign=stripe-secret-bundle#scan. The fix report is $9, or $29 for 10. A full refund is available within 30 days of purchase, no questions asked (refund policy). Prices are on the pricing section.
Rotate the key, then read the logs
Treat a secret or restricted key in the bundle as exposed. Stripe says if a restricted or secret key is exposed or compromised, rotate it immediately even if you are not sure anyone saw it, and treat any exposure as a potential compromise. Exposure means the key became visible somewhere it should not have been, such as a public repository, a log file, or an email (best practices).
Stripe's steps for a compromised secret key are on Protecting against compromised API keys:
- Find the key in the Dashboard → Developers → API keys.
- Open the overflow menu (⋯) and select Rotate key. That creates a new key and sets the compromised key to expire.
- Choose an expiration long enough to test the integration with the new key. The Expiration dropdown includes Now. If you choose Now, the old key is deleted. If you choose a later time, both keys work until then, for up to 7 days. Then click Rotate API key. Copy the new value when Stripe shows it. In live mode you cannot reveal a secret you created yourself after that (API keys).
- Update the backend to the new key. Keep the new key out of client code and out of
VITE_andNEXT_PUBLIC_. - Confirm the integration. On the new key, open the overflow menu and select View request logs.
- If the old key was not deleted by choosing Now, delete it from its overflow menu with Delete key. Deletion is immediate. You can still open request logs for the deleted key. Code that sends an expired or deleted key can no longer make API calls.
Then review what the old key did. Stripe's remediation list:
- In Workbench, review recent use of the key for activity that does not match your integration. From the API keys list, View request logs opens Workbench. Look for unexpected charges, refunds, or connected accounts. If the key has no IP address restriction, look for addresses you do not recognize.
- Refund fraudulent charges as soon as you can (Refunds). With the key, a bad actor can do anything the key allows, including creating charges or subscriptions, issuing refunds, and accessing customer data.
- If you see connected accounts, payouts, or external bank accounts you do not recognize, pause payouts to them or reject them (Pause payments or payouts). Reverse payouts already sent to fraudulent bank accounts and remove those bank accounts (Payout reversals). Reversals are not guaranteed. If you need help reversing payouts, contact Stripe support. On a Connect platform, a compromised key can also change payout destinations, create payouts, and create connected accounts.
- Rotate every other secret and restricted key, in case more than one was exposed.
Stripe's API key security notice says to reach out to support if you have concerns about a key's security (User Notice — API Key Security). Webhook signing secrets are not API keys. Each endpoint has its own, in the Webhooks section of the Dashboard. Roll that secret from the Webhooks tab in Workbench when you suspect the signing secret itself is compromised (API keys, Manage webhook endpoints). If Stripe finds an exposed secret or restricted key, they notify you and ask you to rotate it. In some cases they deactivate the key. They do not guarantee they will find every exposed key (best practices).
Create the Checkout Session on the server
Put the new key in STRIPE_SECRET_KEY, with no public prefix. That is the server name in Stripe's Checkout quickstart for Next.js. The publishable key can stay in NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY or a VITE_ name, because it is a pk_ key. Prefer a restricted key with only the permissions that server code needs (Restricted API keys, best practices). The Node library sends the key you pass to the constructor (Authentication).
The route below creates a Checkout Session the way the Create a Checkout Session example does: mode, a Price id, a quantity, and success_url. Stripe says to keep price and availability on the server to prevent customer manipulation from the client, and to set the product with a predefined Price id when you create the session (Checkout quickstart). This route returns session.url. Creating a PaymentIntent or a refund is also a Stripe API call, so it uses the same server-side key (Authentication).
// app/api/checkout/route.ts
import Stripe from "stripe";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY || "");
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://example.com/success?session_id={CHECKOUT_SESSION_ID}",
});
return Response.json({ url: session.url });
}The page calls that route and sends the visitor to the URL Stripe returns:
const res = await fetch("/api/checkout", { method: "POST" });
const data = await res.json();
window.location.href = data.url;If the page also loads Stripe.js, that script uses the publishable key. That is the key Stripe says you can put in front-end code (API keys).
A Vite app has no Next.js route handler. Put the same checkout.sessions.create call in a serverless or edge function that reads STRIPE_SECRET_KEY from the host's server environment. Do not prefix that name with VITE_. Vite's production advice for secrets is a backend server or a serverless or edge function (Env variables and modes).
Redeploy, then search the live bundle again
Rotate first, then remove the old value from the client. While the old key still has time left on it, Stripe accepts it, including from the copy in the JavaScript. After you delete it, or if you chose Now, code that sends it can no longer make API calls. The string can still be sitting in the bundle. Remove the client import and the public env name, rebuild, and redeploy. Next.js freezes NEXT_PUBLIC_ at next build, and Vite replaces import.meta.env at build time, so a dashboard edit does not change a bundle already shipped.
Search the live JavaScript again for sk_live_, rk_live_, sk_test_, and rk_test_. Run the free scan again. The scan matches sk_live_, rk_live_, and sk_test_ keys in the downloaded files. A deleted key that is still in the JavaScript still matches until visitors load a build without that string. If the replacement key was written into the same public variable, it is exposed too. Stripe says to rotate again after you fix that, and to repeat until no live key is exposed (Protecting against compromised API keys).
FAQ
Is the Stripe publishable key safe in the browser?
Yes. Publishable keys (pk_, including pk_live_ and pk_test_) are the keys Stripe says are safe in front-end code, including Stripe.js. They can identify your account and create tokens or PaymentMethods. They cannot create charges or read account data. Secret keys (sk_) and restricted keys (rk_) are not safe to expose.
Is an sk_test_ key dangerous if it is in the bundle?
Sandbox and live mode use different keys, and an object in one mode is not available in the other. In a sandbox, card networks and payment providers do not process payments. sk_test_ is still a secret key. Stripe says to audit sandbox keys along with live keys, and if you find a sensitive key, assume it has been exposed and compromised. Rotate it.
Does a private repository protect a Stripe secret key?
No. Stripe says never to put secret API keys in source code. Bad actors continuously scan public repositories, and even private repositories can be exposed through development environments. A private repo also leaves a VITE_ or NEXT_PUBLIC_ value in the JavaScript the site sends to visitors. Vite and Next.js inline those prefixes at build time.
Does rotating the Stripe key break my app?
Rotating creates a replacement and sets the old key to expire. On the API keys page, Expiration includes Now. If you choose Now, the old key is deleted, and code that still sends it can no longer make API calls. If you choose a later time, both keys work until then, for up to 7 days. Update the server to the new key before the old one expires or you delete it. The publishable key is a separate key, and Stripe says you cannot expire a publishable key.
Sources
- Stripe: API keys
- Stripe: Best practices for managing secret API keys
- Stripe API: Authentication
- Stripe Support: Protecting against compromised API keys
- Stripe: User Notice — API Key Security
- Stripe: Restricted API keys
- Stripe: Refund and cancel payments
- Stripe: Pause payments or payouts on connected accounts
- Stripe: Payout reversals
- Stripe: Manage webhook endpoints
- Stripe: Checkout quickstart (Next.js)
- Stripe API: Create a Checkout Session
- Vite: Env variables and modes
- Next.js: Environment variables
- Next.js: Data security
- Advance Intelligence, November 18, 2026: viral post on leaked keys in a Cursor and Claude booking app
Check your app now — free, passive, about 20 seconds.
Same scanner as the homepage scan. Paste the live URL. It reads what a visitor already downloads. It does not log in or query your database.
Related guides
- GitHub token in the frontend
- CheckVibe alternatives
- OpenAI API key in the frontend
- Claude Code settings.local.json keys
- Bolt environment variables vs Secrets
- v0 app security checklist
- Cursor app security checklist
- NEXT_PUBLIC_ and VITE_ API keys
- Lovable app data exposure check
- Supabase 42501 permission denied
- Supabase RLS checklist
- Bolt Supabase API key visible
- Supabase service_role key exposed
- Lovable app security check
- Is my vibe-coded app secure?
Scan by builder