Skip to content
Back to skills

Build Webhook Handler

ASecurity

Implements a webhook receiver with signature checks, replay protection, idempotent processing, fast acknowledgement, async work, retries and tests. Use when integrating Stripe, GitHub or similar.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 26, 2026
ai-agentspythonrustgofastapigitapidatabase

Works with

  • api

Security analysis

A100/100

Scanned November 26, 2026

npx -y skills add hermes-hq/hodios-dist --skill build-webhook-handler --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Build Webhook Handler?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Build Webhook Handler
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hermes-hq-build-webhook-handler/badge)](https://www.skillsdirectory.com/skills/hermes-hq-build-webhook-handler)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: build-webhook-handler
description: Implements a webhook receiver with signature checks, replay protection, idempotent processing, fast acknowledgement, async work, retries and tests. Use when integrating Stripe, GitHub or similar.
license: CC0-1.0
arguments:
  - provider
  - events
  - stack
  - signature_scheme
argument-hint: <provider> <events> [stack] [signature_scheme]
disable-model-invocation: true
metadata:
  version: 1.0.1
  kind: prompt
  category: implementation
  source: https://hermes-ide.com/prompts/build-webhook-handler
  catalog: 2026.1014.1
---

# Build a webhook handler

## Inputs

- `provider` (required): Who sends the webhooks, for example Stripe, GitHub, Shopify, Twilio or an internal service.
- `events` (required): The event types to handle and what the app must do for each.
- `stack` (optional): Language and framework, for example "Python FastAPI with Celery". Leave empty to detect it from the repo.
- `signature_scheme` (optional): How the provider signs requests (header names, algorithm, what is signed, timestamp tolerance), pasted from its docs. Needed for providers the assistant cannot verify.

Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.

<context>
Webhook endpoints are public URLs that move money, permissions or data, so they fail in costly ways: a framework parses the JSON before the signature is checked and the raw bytes are gone, so verification never works and someone disables it; a forged or replayed request is accepted; the provider retries after a slow response and the order ships twice; events arrive out of order and an old "subscription.updated" overwrites a newer one; one failing event blocks the endpoint and the provider disables it. A good handler verifies first, acknowledges fast, processes exactly once per event id, and treats the payload as a hint to fetch current state when order matters.
</context>

<task>
Implement a webhook receiver for $provider.
Only if stack was provided: 
Stack: $stack
If no stack is given, detect the language, framework and job queue from the repo and follow their conventions.

Events to handle:
<events>
$events
</events>

Only if signature_scheme was provided: 
Signature scheme from the provider's docs:
<signature_scheme>
$signature_scheme
</signature_scheme>

1. Establish the signature scheme: header names, algorithm, exactly which bytes are signed (often a timestamp plus the raw body), encoding, the event id field and any timestamp tolerance. Use the scheme given above; if none was given and you know the provider's documented scheme (for example Stripe's `Stripe-Signature` header with a timestamp and HMAC-SHA256, or GitHub's `X-Hub-Signature-256` HMAC-SHA256 of the raw body with the `X-GitHub-Delivery` id), state it and tell the user to confirm it against the current docs. If the provider's official SDK is already a dependency and has a verification helper, use it. If you do not know the scheme, stop and ask for it.
2. Read the existing routing, auth middleware, body parsing, job queue, database access and error handling in the repo, and reuse them.
3. Build the endpoint:
   - Read the raw request body before any JSON parsing, and verify the signature over those exact bytes with a constant-time comparison. Reject with 400 or 401 and no detail on failure.
   - Enforce the timestamp tolerance where the scheme signs a timestamp, to block replays.
   - Support more than one active secret so the secret can be rotated without downtime.
   - Enforce a body size limit and accept only the expected content type.
   - Exempt the route from CSRF protection and session auth, and from any middleware that consumes the body.
4. Make processing idempotent and fast:
   - Record the event id in a table with a unique constraint; if it already exists, acknowledge with 2xx and do nothing.
   - Persist the event and enqueue the work, then return 2xx quickly (well within the provider's timeout); do the real work in a background job. Storing and enqueueing are two writes: enqueue through an outbox or the same transaction where the queue allows it, or add a sweeper that picks up stored events still unprocessed after a few minutes, so a failed enqueue never loses an acknowledged event.
   - In the job, handle each listed event type in its own function; ignore and log unknown types with 2xx so new provider events do not cause retries.
   - Guard against out-of-order delivery: compare the event's created time or object version with what is stored, or fetch the current object from the provider's API before acting when order matters.
   - Make the side effects themselves idempotent (upserts, state checks, idempotency keys on outbound calls).
5. Handle failures: return 5xx only when the event could not be stored (so the provider retries); retry the background job with backoff; send events that keep failing to a dead-letter state with the error, and provide a way to replay a stored event.
6. Write tests: valid signature accepted, tampered body rejected, wrong secret rejected, stale timestamp rejected, the same event delivered twice processed once, out-of-order events handled, unknown event type acknowledged, and the background job's happy path and failure for each handled event. Build test signatures with a test secret, never a real one.
7. Run the tests and the linter, and report the real results.
</task>

<constraints>
- Never log the raw signature, the secret or full payloads that contain personal or payment data; log the event id and type.
- Do not trust any field in the payload for authorization beyond what the verified signature covers.
- Do not invent provider headers, event names or fields. Use only what the docs or the user gave, or say what you assumed and that it needs checking.
- Do only what was asked. If you notice something else worth changing, mention it in one line at the end instead of changing it.
- Keep the change as small as it can be while still being correct.
- Before saying the work is done, run the check that proves it (tests, build, type check or the command the user gave) and report the real result.
- If you could not run a check, say so plainly and say which one.
</constraints>

<output_format>
## Signature scheme
What is signed, the headers, algorithm and tolerance, and the source (user-provided, SDK, or from memory: confirm against the provider's docs).
## Design
A Mermaid sequence diagram from the provider to the side effect, then the idempotency and ordering strategy in a few bullets.
## Changes
One line per file.
## Tests
One line per test and the real result of the run.
## Configuration
| Setting | Env var | Required | Notes | (secrets, tolerance, queue names)
## Operational notes
How to register the endpoint with the provider, rotate the secret, replay a failed event, and what to alert on.
</output_format>

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.