/hardening:webhook-reliabilityfrom hardening
Design or review inbound and outbound webhooks for signature verification, idempotency, retry/backoff, dead-letter recording, replay tooling, and timeout budgets. Use when building a new webhook handler or emitter, reviewing an existing one (Stripe, GitHub, or a custom outbound webhook), or investigating a "webhook silently didn't fire" report.
Ships in hardening. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Webhooks fail silently by nature — there's no user staring at a spinner when one drops, so the failure mode is "data quietly went stale" discovered days later. This skill covers both directions: inbound (Stripe, GitHub sending events to us) and outbound (if your product emits webhooks to third parties or customers). The core disciplines — verify, dedupe, retry, record dead letters, monitor — apply to both.
Signature verification is mandatory, always, first line of the handler — never process a payload before verifying it came from the claimed sender:
// Read the raw body once, before any parsing — req.json() first means the bytes no longer match the signature
const rawBody = await req.text();
// Stripe
const event = stripe.webhooks.constructEvent(rawBody, req.headers.get('stripe-signature')!, process.env.STRIPE_WEBHOOK_SECRET!);
// GitHub
import { createHmac, timingSafeEqual } from 'crypto';
const sig = Buffer.from(req.headers.get('x-hub-signature-256') ?? '');
const expected = Buffer.from('sha256=' + createHmac('sha256', process.env.GITHUB_WEBHOOK_SECRET!).update(rawBody).digest('hex'));
if (sig.length !== expected.length || !timingSafeEqual(sig, expected)) {
return new Response('Invalid signature', { status: 401 });
}
Use timingSafeEqual, never ===, for signature comparison — a naive string comparison leaks timing information. timingSafeEqual throws a RangeError (ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH) when the buffers differ in length, so check lengths first or a malformed header turns into a 500 instead of a 401.
Idempotency — providers can deliver the same event more than once (Stripe retries; a GitHub redelivery reuses the original id). Record the provider's event id in a table with a unique constraint — Stripe's event.id, or GitHub's X-GitHub-Delivery header, which "will be the same as in the original delivery" on a redelivery (GitHub: best practices for using webhooks):
model WebhookEvent {
id String @id @default(cuid())
provider String // "stripe" | "github"
externalId String // event.id from the provider
receivedAt DateTime @default(now())
@@unique([provider, externalId])
}
try {
await prisma.$transaction(async (tx) => {
await tx.webhookEvent.create({ data: { provider: 'stripe', externalId: event.id } });
await applyEvent(tx, event); // or enqueue the job inside the same transaction
});
} catch (e) {
if (isUniqueConstraintError(e)) return new Response('Already processed', { status: 200 });
throw e; // non-2xx, so the provider can retry
}
Write the idempotency record only together with successful processing (same transaction), or after it — never before. If the id is committed first and the handler then fails, the retry looks like a duplicate, gets skipped, and the event is lost.
Timeout budget — providers expect a fast ack (Stripe: respond within a few seconds or it's treated as a failed delivery and retried; GitHub: respond with a 2xx within 10 seconds or the delivery is marked failed). Do the minimal synchronous work (verify + record + enqueue), push anything slow (sending a welcome email, recomputing analytics) to a background job rather than doing it inline before responding.
Return the right status code — 2xx only after the event is durably recorded (not necessarily fully processed if processing is async). Any failure to verify/record should return non-2xx so the provider retries — swallowing an error and returning 200 anyway is the single most common cause of silent data loss.
Know who retries — Stripe retries failed live-mode deliveries for up to 3 days. GitHub does not: "GitHub does not automatically redeliver failed webhook deliveries" (GitHub: handling failed webhook deliveries). Redeliver from the UI or REST API, or run a scheduled job that lists failed deliveries and redelivers them. Check each provider's policy before relying on its retries.
Dead-letter recording — providers don't write dead letters for you. When your own background processing exhausts its retries, your job writes a durable record, not just a log line that scrolls away:
model WebhookDeadLetter {
id String @id @default(cuid())
provider String
externalId String
payload Json
lastError String
failedAt DateTime @default(now())
}
Alert on rows appearing here: one row opens a ticket, and a burst above an hourly count pages someone (the observability-setup skill in the release-ops pack has the threshold table). A Better Stack log-based alert on the "dead letter recorded" log line, or a simple count check, covers both. A dead letter with no one looking at it is worse than no dead-letter table at all, because it creates false confidence.
Replay tooling — a small internal script or admin route to re-fetch a stored dead-letter payload and re-run it through the same handler logic, so recovering from a bug doesn't require asking the provider to manually resend:
// scripts/replay-webhook.ts
const dl = await prisma.webhookDeadLetter.findUniqueOrThrow({ where: { id: deadLetterId } });
await processStripeEvent(dl.payload as Stripe.Event); // same function the live handler calls
await prisma.webhookDeadLetter.delete({ where: { id: deadLetterId } });
429, 502, or 504, slow down and honor any Retry-After; on 410 Gone, stop and disable the endpoint.msg_id.timestamp.payload) so receivers can reject stale replays by checking the timestamp is within a tolerance.Show the user: the signature verification code path, the idempotency table/constraint, a captured example of a duplicate delivery being correctly skipped (log line or test), and the dead-letter table schema plus how it's monitored. For an audit of an existing webhook, report which of the above are present vs missing per handler.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub stylusnexus/agent-plugins --plugin hardening12 skills in this plugin
/agent-tooling-reviewUse when connecting, auditing, or widening the permissions of tooling an AI agent can call: MCP servers, plugins, skills, database or GitHub connections, API tokens issued to an agent, or an agent that will run unattended (scheduled, looped, event-triggered, background, CI). Triggers: a new MCP or plugin is about to be added, an agent needs write access it did not have, a connection points at production, an unattended job is being set up, or a tool's description changed after approval./auth-hardeningNextAuth v5 security audit and hardening checklist — session/cookie config, CSRF, OAuth scopes, per-route role checks, password-reset/OTP rate limits, secret rotation, session invalidation on privilege change. Use when adding auth to a new product, auditing an existing NextAuth v5 app, or reviewing any PR that touches session/role/permission code./exposure-scanScan installed packages against bumblebee threat-intelligence exposure catalogs to detect known-compromised dependency releases from supply-chain campaigns. Use when checking for compromised packages, running a supply-chain or dependency security scan, auditing the machine after a reported npm/PyPI/Go/gem/extension compromise, or refreshing threat-intel catalogs./legal-docsDraft or review the customer-facing legal documents of a small SaaS - Terms of Service, Privacy Policy, refund policy, and acceptable use policy - in plain English, with placeholders instead of invented facts, a check that every claim matches what the product actually does, and a not-legal-advice notice on every draft. Use when asked to "write terms", "draft a privacy policy", "update our ToS", "write a refund policy", or before launching a product or feature that changes what data is collected or how billing works./llm-app-securityUse when a product feature sends untrusted content to a language model or lets a model call tools, write data, send messages, or render output to other users. Triggers: a new chat, RAG, summarization, agent, or tool-calling feature; a model that reads web pages, documents, emails, tickets, or other users' text; a 'can prompt injection reach this' question; a pre-launch review of anything with an LLM in the request path; or an incident where a model did something nobody asked for./privacy-auditData inventory and privacy audit for a product — enumerate exactly what user data is collected and where it lands (Neon/Supabase tables, logs, PostHog, Stripe, email provider, Better Stack/Sentry), check alignment with the privacy policy, verify GDPR export/delete paths exist, and grep for PII leaking into logs or API responses. Use when asked to "audit privacy," "check what data we collect," before a launch, or after adding a new data-collecting feature (signup field, analytics event, webhook).Other plugins' skills for the same job