AI builders sometimes paste the Stripe secret key straight into the code, or into an environment variable the browser can read. Stripe is blunt about what that means: "If an unauthorized party obtains your secret API key, they can make unauthorized charges, access customer data, or disrupt your integration" (Stripe docs: Best practices for managing secret API keys).
pk_live_ / pk_test_ is the publishable key. Stripe: "Only publishable keys are safe to expose outside your application's back end" (Stripe docs: API keys). Seeing a pk_ key in the page source is normal. sk_ (secret) and rk_ (restricted) keys must never be there.VITE_ will be exposed in client-side source code after Vite bundling" and "VITE_* variables should not contain sensitive information such as API keys" (Vite docs: Env variables and modes). Next.js: a NEXT_PUBLIC_ variable "will be inlined into any JavaScript sent to the browser" (Next.js docs: Environment variables). So VITE_STRIPE_SECRET_KEY or NEXT_PUBLIC_STRIPE_SECRET_KEY means the key is public, whatever the name says.sk_live_ and rk_live_. Do the same in your repository.Stripe: "If a restricted or secret API key is exposed or compromised, rotate it immediately even if you aren't sure anyone saw it. Treat any exposure as a potential compromise" (source).
VITE_ or NEXT_PUBLIC_ prefix, read only from a server route, Edge Function or Worker. Stripe: "Never embed secret API keys in applications" and use publishable keys for client-side code (source).If the same file or bundle also held your whsec_ signing secret, anyone with it can sign fake "payment succeeded" events that your webhook will accept as real. Roll it: in Workbench → Webhooks, open the endpoint, overflow menu → Roll secret. You "can choose to immediately expire the current secret or delay its expiration for up to 7 days" (Stripe docs: Roll endpoint signing secrets). For a leaked secret, expire it now and update your server's env var. The signing secret belongs on the server only, same as the API key (see test vs live webhook secret).
// Client (browser): publishable key only
const stripe = await loadStripe(import.meta.env.VITE_STRIPE_PUBLISHABLE_KEY); // pk_live_...
// Server route / Edge Function / Worker: restricted or secret key, never shipped to the browser
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY); // rk_live_... preferred
const secret = process.env.STRIPE_WEBHOOK_SECRET; // whsec_..., server only
// Never:
// VITE_STRIPE_SECRET_KEY=sk_live_...
// NEXT_PUBLIC_STRIPE_SECRET_KEY=sk_live_...
// const stripe = new Stripe('sk_live_...') (hard-coded in any file)
Variable names are examples; use your host's secret settings (Vercel, Supabase Edge Function secrets, Cloudflare Worker secrets) for the values.
My Stripe secret key was exposed. I have already rotated it in the Stripe Dashboard. 1) Search the whole codebase and config for sk_live_, sk_test_, rk_live_, rk_test_ and whsec_ and remove every hard-coded value. 2) Make sure no Stripe secret or webhook secret is in a VITE_ or NEXT_PUBLIC_ variable or anything bundled for the browser; the browser may only use the publishable key (pk_). 3) Read STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET only in server-side code (API routes, Edge Functions, Workers). 4) Move every Stripe API call that uses the secret key (creating Checkout Sessions, refunds, reading customers) to a server route the frontend calls. 5) Add .env files to .gitignore. 6) Do not change the webhook's signature verification or fulfillment logic.
sk_, rk_ and whsec_: no matches.4242 4242 4242 4242 and confirm the webhook still returns 2xx and unlocks the account.Paste your webhook URL. WebhookProof sends 3 harmless test requests and tells you whether Stripe can reach it and whether it rejects unsigned events. If it finds a problem, the $9 fix pack gives you the exact copy-paste fix for your stack (refundable for 14 days).
Run the free checkYes. Stripe says only publishable keys (pk_live_ / pk_test_) are safe to expose outside your back end. Secret (sk_) and restricted (rk_) keys must stay on the server.
Yes. Vite exposes VITE_ variables in client-side code after bundling, and Next.js inlines NEXT_PUBLIC_ variables into JavaScript sent to the browser. Rotate the key and move it to a server-only variable.
Rotate it immediately in the Stripe Dashboard, even if you are not sure anyone saw it, then check request logs for calls you did not make. Removing it in a later commit does not remove it from history.
If the whsec_ secret was exposed as well, roll it from the webhook endpoint in Workbench and expire the old one, because anyone with it can sign fake events your endpoint would accept.
Stripe webhook not working? Check these 7 things in order · A customer paid but didn't get access. What went wrong? · No signatures found matching the expected signature for payload · Stripe webhook failing with a 307 or 308 redirect
Last reviewed 2026-11-11. WebhookProof is an independent tool, not affiliated with Stripe, Inc.. Quotes are from the linked documentation.