A classic SaaS bug is unlocking paid features when the user hits /checkout/success?session_id=... . Users can close the tab before redirecting—or replay parameters manually.
Always Fulfill Inside Verified Webhooks
Verify the cryptographic signature using the raw request buffer (not parsed JSON).
Store processed event.id values inside an atomic database transaction to prevent duplicate fulfillment when Stripe retries.
import Stripe from 'stripe'
const stripe = new Stripe ( process . env . STRIPE_SECRET_KEY ! )
export async function processWebhook ( rawBody : Buffer , sig : string ) { const event = stripe . webhooks . constructEvent ( rawBody , sig , process . env . STRIPE_WEBHOOK_SECRET ! ) // Check if event.id already exists in DB, then grant access atomically return { received : true , type : event .…