Stripe SaaS Webhooks Done Right: Why Client Redirects Are Not Payment Proof
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 Webhoo
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.idvalues 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.type }
}
Want Production-Ready .cursorrules & Boilerplates?
I'm a student developer in Japan funding my upcoming new life next spring by packaging strict, battle-tested AI coding setups:
-
Free Starter
.cursorrules& Reviewer Prompts ($0+): Download Free Starter Pack (or GitHub Repo) - 10-in-1 Ultimate Developer Suite ($19): Get Stack Kit
- All 10 Production Stacks Bundled ($99): 10-in-1 Ultimate Developer Suite
📰 Read the original article on Dev.to Security
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.