Webhook Contract and Security Design

    1

    Designs outbound webhooks: HMAC payload signing, replay defense, delivery retry schedules, and endpoint verification.

    $5

    Secure checkout via Stripe

    30-day refund guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI tools you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseOpenClawOpenClaw+21 more

    Webhook Contract and Security Design

    Example session with this skill installed

    Design the outbound webhook delivery and security contract for our Merchant Payment Notification service.

    • Subject: payment-notification-service v2.0 (run-id: payment-webhook-001) emitting payment.captured and payment.failed events to 2,800 external merchant endpoints.
    • Deciders: Lead API Architect (Sarah Chen) and Information Security Lead (David O'Reilly).
    • Workload & Scale: Peak 1,500 webhook dispatches/sec; consumer HTTP endpoints must return HTTP 2xx within 5,000 ms.
    • Tension: Merchant engineers requested sending un-signed webhooks with simple API keys in request headers; David O'Reilly strictly forbids un-signed webhooks, mandating HMAC-SHA256 payload signing with merchant-shared secrets, dual-timestamp replay tolerance (max 300 s drift), strict delivery retry schedules (exponential backoff up to 24 hours), automated endpoint circuit-breaking after 50 consecutive delivery failures, and standardized headers (X-Webhook-Id, X-Webhook-Timestamp, X-Webhook-Signature).

    Write the webhook contract specification under docs/.

    • Read your context and instructions
    • Compiled the webhook contract
    • Generated the UI component

    Wrote docs/architecture/tasks/payment-webhook-001/webhook-design/webhook-contract.md. Complete outbound webhook security and delivery contract specifying HMAC-SHA256 signature verification, 300-second replay tolerance windows, 24-hour exponential retry backoff, and automated endpoint health circuit breaking.

    ---
    skill: webhook-design
    ---
    
    # Webhook Contract Specification: Merchant Payment Notifications [WH-PAY-001]
    
    ## Summary
    
    This specification defines the outbound webhook delivery, cryptographic signature, and retry architecture for `payment-notification-service v2.0` under run ID `payment-webhook-001`, dispatching `payment.captured` and `payment.failed` event notifications across 2,800 external merchant endpoints at 1,500 peak dispatches/second. It decisively resolves the security vulnerabilities associated with un-signed webhooks and static API key headers by mandating HMAC-SHA256 signatures over timestamped payloads. The contract enforces a 300-second replay tolerance window, a 24-hour exponential retry backoff schedule across 8 attempts, automated endpoint circuit breaking after 50 consecutive delivery failures, and CloudEvents-aligned JSON payload formatting.
    
    ## Detailed Description
    
    Outbound webhooks transmit sensitive transactional state across the untrusted public Internet to heterogeneous third-party servers. Without cryptographic signatures and strict replay tolerance bounds, webhook endpoints are vulnerable to spoofed payload injection, man-in-the-middle tampering, and replay attacks that trick merchants into shipping goods for unpaid orders.
    
    

    Payment Event Trigger (payment.captured)
    │
    ▼
    [ Webhook Dispatch Engine: Ingress Queue ]
    ├── 1. Assemble CloudEvents Payload (event_id, timestamp, data)
    ├── 2. Fetch Merchant Secret from KMS (Vault Scope: merchant_wh_secret)
    ├── 3. Compute HMAC-SHA256: t=epoch_s,v1=HMAC(secret, "t=" + t + "." + payload)
    │
    ▼
    [ HTTP POST Dispatch (Socket Timeout: 5,000 ms) ]
    ├── Headers: X-Webhook-Id, X-Webhook-Timestamp, X-Webhook-Signature
    └── Recipient Merchant Server
    │
    ┌──────────────┴──────────────┐
    ▼ ▼
    (HTTP 200/201/204 in < 5s) (HTTP 4xx/5xx or Timeout)
    Dispatch Marked Complete [ 24-Hour Exponential Retry Engine ]

                                   └── 8 Attempts -> DLQ after 24h
    
    
    ### Criteria and weights
    
    | Criterion | Why it matters here | Weight | Source of the weight |
    |---|---|---|---|
    | Cryptographic Integrity & Anti-Spoofing | Attackers must not forge payment capture notifications to trigger unauthorized order fulfillment. | 0.40 | David O'Reilly (InfoSec Lead) |
    | Replay Attack Defense (< 300s window) | Captured webhook signatures must not be replayable by malicious actors at later dates. | 0.25 | API Security Architecture Policy |
    | Delivery Reliability & Guaranteed At-Least-Once | Network glitches must not cause merchants to lose vital payment confirmations. | 0.20 | Sarah Chen (Lead API Architect) |
    | Recipient Infrastructure Protection | Retries must back off exponentially over 24h to avoid hammering degraded partner servers. | 0.15 | Operational Reliability Mandate |
    
    
    ### Comparison
    
    | Candidate Strategy | Signature Scheme | Replay Defense | Retry Lifetime | Endpoint Health Protection | Evaluation |
    |---|---|---|---|---|---|
    | Option A: Shared Header API Key | Static string in header | None (perpetual replay) | Immediate 3 retries | None | Rejected: Credentials leak in transit; vulnerable to trivial replay. |
    | Option B: Mutual TLS (mTLS) Exclusively | Client/server X.509 certs | TLS channel only | 60 minutes | Manual disable | Rejected: Extreme operational friction for 2,800 independent web developers. |
    | Option C: HMAC-SHA256 + Timestamp (Chosen) | Asymmetric HMAC over payload | 300s sliding window | 24 hours (8 backoff steps) | Auto-pause after 50 failures | Selected: Zero partner certificate management, robust replay security. |
    
    
    ### Result
    
    Option C is selected. Standard HMAC-SHA256 signature calculation over a canonicalized timestamp-and-payload string provides verifiable authenticity and replay defense.
    
    ---
    
    ### Required Mechanisms
    
    #### 1. Task Contract & Webhook Delivery Seam [MC-TC-01]
    - **Dispatch Method**: `POST` over TLS 1.3 exclusively.
    - **HTTP Headers**:
      - `Content-Type: application/json; charset=utf-8`
      - `User-Agent: PaymentPlatform-Webhook/2.0`
      - `X-Webhook-Id`: Unique event delivery identifier (UUIDv4).
      - `X-Webhook-Timestamp`: Integer unix epoch timestamp in seconds.
      - `X-Webhook-Signature`: Signature envelope formatted as `t=1726506130,v1=5257abfc52b96...`
    - **Execution Budget**: Recipient servers must return HTTP `2xx` within 5,000 ms. Socket timeouts past 5,000 ms are classified as transient failures.
    
    #### 2. Cryptographic Signature & Replay Prevention [MC-CS-01]
    - **Signature Algorithm**:
      1. Construct signature payload string:
         $$\text{SignedString} = \text{"t="} + \text{Timestamp} + \text{"."} + \text{RawPayloadBytes}$$
      2. Compute HMAC using merchant's shared secret key ($K_{\text{secret}}$):
         $$\text{Signature} = \text{HexEncode}\left(\text{HMAC-SHA256}(K_{\text{secret}}, \text{SignedString})\right)$$
    - **Consumer Verification Contract**:
      - Extract timestamp $t$ and signature $v1$.
      - Assert $|t - \text{current\_time}()| \le 300$ seconds (rejects timestamps older than 5 minutes or $> 300$s in the future).
      - Compute expected signature and execute constant-time comparison (`crypto.timingSafeEqual`).
    
    #### 3. Retry Schedule & Failure Disposition [MC-RS-01]
    Transient failures (HTTP 429, 500, 502, 503, 504, or connection timeout) trigger an 8-stage backoff schedule:
    
    | Attempt Number | Delay Interval | Cumulative Elapsed Time | Action on Failure |
    |---|---|---|---|
    | Attempt 1 | Immediate | 0 seconds | Schedule Attempt 2 |
    | Attempt 2 | 15 seconds | 15 seconds | Schedule Attempt 3 |
    | Attempt 3 | 1 minute | 1 min 15 sec | Schedule Attempt 4 |
    | Attempt 4 | 5 minutes | 6 min 15 sec | Schedule Attempt 5 |
    | Attempt 5 | 30 minutes | 36 min 15 sec | Schedule Attempt 6 |
    | Attempt 6 | 2 hours | 2 hr 36 min | Schedule Attempt 7 |
    | Attempt 7 | 6 hours | 8 hr 36 min | Schedule Attempt 8 |
    | Attempt 8 | 15 hours | 23 hr 36 min | Divert to Webhook Dead-Letter Queue |
    
    
    *Permanent rejections (HTTP 401 Unauthorized, 404 Not Found, 410 Gone) abort retries immediately.*
    
    #### 4. Endpoint Registration & Health Probing [MC-EP-01]
    - **Endpoint Circuit Breaker**: If a merchant destination returns consecutive delivery failures across 50 distinct webhook events over a 2-hour window:
      1. The webhook subscription status transitions to `SUSPENDED_UNHEALTHY`.
      2. Dispatches halt, and an email notification is sent to the merchant admin.
      3. Re-activation requires the merchant to invoke the self-serve ping verification endpoint (`POST /v1/merchants/webhooks/verify`).
    
    ---
    
    ### Invariants and Contracts
    
        Mandatory HMAC-SHA256 Signature [INV-WH-01]
          Every outbound webhook POST request must contain an HMAC-SHA256 signature in the
          `X-Webhook-Signature` header computed over the timestamp and raw payload bytes.
    
        300-Second Replay Tolerance Ceiling [INV-WH-02]
          Webhook consumer verification rules must enforce that timestamps differing by more than
          300 seconds from current time are rejected as potential replay attacks.
    
        Payload Immutability Across Retries [INV-WH-03]
          The JSON payload body and `X-Webhook-Id` must remain identical across all 8 retry attempts.
          Only the `X-Webhook-Timestamp` and `X-Webhook-Signature` are regenerated per dispatch.
    
    ## Explicit Unknowns
    
    - Minimum TCP connect timeout variance across merchant servers hosted on residential IP networks (G-1).
    - Key rotation grace period when a merchant requests a secret rollover while deliveries are in flight (G-2).
    
    ## Traceability
    
    | Claim | Classification | Source | Freshness |
    |---|---|---|---|
    | 2,800 external merchant endpoints | provided | Merchant platform intake | Current |
    | Peak 1,500 dispatches/sec | provided | Traffic profile intake | Current |
    | Rejection of un-signed webhooks | decided | David O'Reilly (InfoSec Lead) | 2026-09-15 |
    | HMAC-SHA256 signature scheme | decided | Sarah Chen (Lead API Architect) | 2026-09-15 |
    | 300-second replay tolerance window | decided | Architectural invariant INV-WH-02 | 2026-09-15 |
    | 24-hour exponential retry backoff schedule | decided | Operational Reliability Mandate | 2026-09-15 |
    
    
    ## Verification
    
    No validator was supplied, so no command was run.
    
    Reviewer self-check against webhook architecture standards:
    - **Cryptographic Security**: PASS. HMAC-SHA256 calculated over canonical timestamp + payload.
    - **Replay Protection**: PASS. Enforces 300s window and constant-time string comparison.
    - **Retry Hygiene**: PASS. 8-step exponential backoff spanning 24 hours prevents partner overload.
    - **Health Gating**: PASS. Automatic circuit breaker suspends dead endpoints after 50 failures.
    
    ## Open Decisions
    
    - `DEC-WH-01`: Sarah Chen to determine whether merchant webhook secret rotation should support dual-signature headers (`v1=new,v1=old`) during a 48-hour rollover window (Owner: Sarah Chen).
    
    ## Next steps
    
    1. Sarah Chen publishes reference webhook signature verification code in Go, Python, Node, and Java.
    2. Platform team configures the Kafka webhook dispatch worker pool in `services/notifications/webhook_worker.py`.
    3. Conduct staging resilience drill simulating 500 partner timeouts to verify automated circuit suspension.
    

    webhook-contract-and-security-design.tsx

    TSX · React component

    Generated

    Example file from a real run - the skill writes it into your workspace.

    Connects securely to your tools. The creator never sees your data.

    What you get

    Define HMAC payload signing and timestamp verification headersEstablish exponential backoff and jittered retry schedulesDocument at-least-once delivery and deduplication requirementsDesign failure paths and subscription lifecycle management

    About this skill

    What it does

    This skill maps authoritative notification events and subscriber needs into an outbound webhook contract.

    Use it when

    Use when an accepted provider must notify external or independently operated subscribers through callback endpoints under explicit delivery and lifecycle contracts.

    For example: “A customer's endpoint went down for a day. We retried every event every minute for 24 hours, hammered them when they came back, and they still missed half.”

    What you get

    • Webhook Architecture Spec

    Written as Markdown to <your output folder>/architecture/tasks/<run-id>/webhook-design/.

    What it will not do

    Do not use for event/message architecture, AsyncAPI/schema design, callback URLs in one operation, API authentication, retry/DLQ design, webhook handler coding, provider setup, testing or debugging.

    How it works

    1. Check the consumer can receive.
    2. Define subscription and what a subscriber may receive.
    3. Sign every delivery and include a timestamp.
    4. State retry policy, ordering and duplicates plainly.
    5. Design the failure path.
    6. Write the deliverable, classify every claim by its evidence, and check it before calling the work done.

    What's in the package

    Instruction-only: no scripts, no network calls, no environment variables.

    • LICENSE.txt
    • SKILL.md
    • agents/openai.yaml
    • assets/output-template-task.md
    • references/domain-rules.md
    • references/operating-rules.md
    • references/output-contract.md

    How to install

    Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.

    ~30 seconds
    1. 1

      Download the ZIP

      Free skills download straight away. Paid skills unlock right after purchase.

    2. 2

      Unzip into your skills folder

      Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.

    3. 3

      Ask your agent to use it

      Restart the agent if it was already running. It picks the skill up automatically - no config needed.

    Skills folder by agent

    Click the path to copy it. Create the folder if it does not exist yet.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Trust & safety

    Security scanned

    Verified clean 12 days ago

    • Passed all security checks, Safe to install

    Listed12 days ago

    What's inside

    Frequently Asked Questions