How to fix: Stripe webhook signing secret in client bundle
Stripe whsec_* values must live server-side. If they show up in client code, attackers can forge webhook events.
Why it matters
An attacker with the webhook signing secret can forge any Stripe event: payments.succeeded, invoice.paid, subscription.deleted, causing your server to credit fraudulent orders, cancel real subscriptions, or trigger payouts without any actual transaction.
Stripe whsec_* values must live server-side. If they show up in client code, attackers can forge webhook events.
How to fix it
- 1Move the webhook secret to an environment variable (STRIPE_WEBHOOK_SECRET)
- 2Verify webhooks server-side only using stripe.webhooks.constructEvent()
- 3Rotate the secret in the Stripe Dashboard under Webhooks
Code examples
Next.js Route Handler: server-side webhook verification
import Stripe from 'stripe';
import { NextResponse } from 'next/server';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function POST(req: Request) {
const body = await req.text();
const sig = req.headers.get('stripe-signature')!;
try {
const event = stripe.webhooks.constructEvent(
body,
sig,
process.env.STRIPE_WEBHOOK_SECRET! // Server-side only
);
// Handle event.type here
} catch (err) {
return NextResponse.json({ error: 'Invalid signature' }, { status: 400 });
}
return NextResponse.json({ received: true });
}.env.local: secret storage
# .env.local (never commit this file)
STRIPE_SECRET_KEY=sk_live_...
STRIPE_WEBHOOK_SECRET=whsec_...
# .gitignore
.env
.env.local
.env*.localReferences
Detected automatically by VulnRadar. The check id is secret-stripe-webhook-endpoint, stable across every scan so you can filter or diff on it.
More secrets checks
Questions
- How severe is Stripe webhook signing secret in client bundle?
- VulnRadar rates this critical severity in the secrets category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id secret-stripe-webhook-endpoint, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Stripe webhook signing secret in client bundle map to?
- It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.