Your Stripe webhook is unverified, and someone can unlock your product for free
Most apps unlock a paid feature when Stripe sends a webhook saying a payment succeeded. The webhook endpoint is a public URL, so the only thing separating a real Stripe event from a forged one is the signature Stripe attaches to every request.
If your handler does not verify that signature, anyone who knows (or guesses) the URL can POST their own "checkout.session.completed" event and flip themselves to paid, for free.
Why it matters
An attacker sends a single crafted request to /api/webhooks/stripe with a body that looks like a successful payment. Your app trusts it, marks the account as subscribed, and grants access. No card, no charge. At scale this is straight revenue loss, and it is trivial to automate.
How do I know if my webhook is safe?
Open your webhook handler and look for one thing: does it verify the signature before trusting the event?
- Safe handlers call stripe.webhooks.constructEvent(rawBody, signatureHeader, endpointSecret) and reject anything that throws.
- Unsafe handlers read req.body directly and act on event.type without ever checking the stripe-signature header.
- The endpoint must receive the raw request body, not a parsed JSON object, or verification will always fail.
Verify every webhook against your endpoint signing secret before you trust it, and read the raw body so the signature check works. Reject anything that does not verify.
- Get the endpoint’s signing secret from the Stripe dashboard (starts with whsec_).
- Read the raw request body (disable body parsing for this route).
- Call constructEvent with the raw body, the stripe-signature header, and the secret.
- Only act on the event if verification passes; return 400 otherwise.
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
export async function POST(req) {
const raw = await req.text(); // raw body, not parsed JSON
const sig = req.headers.get('stripe-signature');
let event;
try {
event = stripe.webhooks.constructEvent(raw, sig, process.env.STRIPE_WEBHOOK_SECRET);
} catch (err) {
return new Response('invalid signature', { status: 400 });
}
if (event.type === 'checkout.session.completed') {
// safe to grant access now
}
return new Response('ok');
}
FAQ
Where do I find the webhook signing secret?
In the Stripe dashboard under Developers, Webhooks, select your endpoint. The signing secret starts with whsec_. It is different from your API secret key.
Why does verification keep failing?
Almost always because the framework parsed the body into JSON before you verified it. Stripe signs the raw bytes, so you must read the raw body (in Next.js App Router use req.text(); in Express use express.raw for that route).