Stripe webhook hardening

From Kevin-Liu-01/Agent-Machines · View interactive version

Stripe webhook hardening is an AI agent skill from the GitHub repository Kevin-Liu-01/Agent-Machines. Harden Stripe webhook handlers against three failure-prone invariants — raw-body signature verification, negative-lifecycle handling, and idempotent side effects. Use when reviewing, implementing, or hardening Stripe webhook routes, or when the user says "stripe webhooks", "webhook hardening", "sign

How to use this skill

Skill file

Stripe Webhook Hardening

Harden Stripe webhook handlers against the three ways generated webhook code most commonly fails in production.

The Three Invariants

1. Raw-Body Signature Verification

The route MUST read the raw request body and verify stripe-signature before any JSON parsing. stripe.webhooks.constructEvent(rawBody, sig, secret) is the only valid entry point.

Failure mode: parsing JSON before constructEvent makes signature verification impossible — the signature covers the raw bytes, not the parsed object.

2. Negative-Lifecycle Handling

Failure and cancellation events (invoice.payment_failed, customer.subscription.deleted) MUST change real product state, not just log.

Failure mode: treating these as log-only events means users keep access after payment failure or cancellation.

3. Idempotent Side Effects

Every side effect MUST be replay-safe. Stripe retries and may deliver the same event more than once.

Implementation options (all valid):

The stronger invariant is that the mutation itself must be replay-safe.

Review Checklist

  1. Does the route read raw request body and verify stripe-signature before any parsing?
  2. Do failure and cancellation events change real product state, not just log?
  3. Is every side effect idempotent under replay?
  4. Are there tests and an operational verification path through the Stripe dashboard?

Architecture

Webhook routes should be thin ingress adapters. Shared billing helpers own verification, dispatch, idempotency, and state transitions. One shared billing path handles all billing mutations.

Dedalus Canon

Verification Workflow

Scope

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.