PAY-002high SeverityPayment Processing & Webhook Integrity

Webhook Idempotency Prevents Double-Credit or Double-Grant

Stripe delivers events multiple times during retries. AI handlers increment balances directly without tracking event.id.

1-Click Fix Prompt for Cursor & Claude Code
Review my codebase for "Webhook Idempotency Prevents Double-Credit or Double-Grant" (PAY-002).
Issue: Stripe delivers events multiple times during retries. AI handlers increment balances directly without tracking event.id.
Remediation required: Store processed Stripe event IDs in a processed_events table and ignore duplicate webhook deliveries.

Please:
1. Locate any occurrences of this issue across my repository.
2. Refactor the code to follow production standards without breaking existing functionality.
3. Provide a clear command or step to test and verify the fix.

Why AI Assistants Write This Bug

Stripe delivers events multiple times during retries. AI handlers increment balances directly without tracking event.id.

AI code generation prioritizes immediate syntax execution over production edge cases. When an assistant hits an undefined variable or strict type error, it frequently takes the path of least resistance rather than implementing standard pre-launch security patterns.

Code Comparison

Common AI Code PatternVulnerable
// Vulnerable AI-generated pattern for: Webhook Idempotency Prevents Double-Credit or Double-Grant
// Flawed Stripe webhook handler
export async function POST(req: Request) {
  const body = await req.json(); // BUG: Fails signature verification!
  const signature = req.headers.get("stripe-signature");
  // Unhandled events drop silently
  return Response.json({ received: true });
}
Launch-Ready Fix
// Production-ready fix for: Webhook Idempotency Prevents Double-Credit or Double-Grant
// Fixed Stripe webhook with raw text buffer
export async function POST(req: Request) {
  const body = await req.text(); // Raw text preserves HMAC signature
  const signature = req.headers.get("stripe-signature");
  const event = stripe.webhooks.constructEvent(body, signature!, process.env.STRIPE_WEBHOOK_SECRET!);
  // Acknowledge receipt with 200
  return Response.json({ received: true }, { status: 200 });
}

Remediation & Verification Checklist

Remediation: Store processed Stripe event IDs in a processed_events table and ignore duplicate webhook deliveries.
  1. Search your codebase for pattern matching "Webhook Idempotency Prevents Double-Credit or Double-Grant".
  2. Apply the recommended remediation: Store processed Stripe event IDs in a processed_events table and ignore duplicate webhook deliveries.
  3. Run local build and test commands to ensure no regressions.
  4. Verify in your browser or with curl that the issue is resolved.
Audit All 108 Checks in One Click

Checking items one by one takes hours. Let us do it in 2 minutes.

With the Founder Pass ($15 one-time), we automatically scan your repository for this issue, plus all other 107 launch checks across secrets, Stripe webhooks, Supabase RLS, and security headers.