Validation points
Express + Stripe example
import express from 'express';
import Stripe from 'stripe';
const app = express();
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY || '');
app.post('/webhook/stripe', express.raw({ type: 'application/json' }), (req, res) => {
const signature = req.headers['stripe-signature'];
const secret = process.env.STRIPE_WEBHOOK_SECRET || '';
try {
const event = stripe.webhooks.constructEvent(req.body, String(signature), secret);
// TODO: handle event with idempotency check
res.status(200).send('ok');
} catch (err) {
res.status(400).send('signature verification failed');
}
});Important
If JSON/body parsers run first, raw payload may change and signature checks can fail.