
Checks that a webhook delivery was signed by its sender, over the raw body, before your handler sees it. Presets for Standard Webhooks, Stripe, Slack, Discord, GitHub, Shopify and Linear; any other sender that signs with HMAC-SHA256 or Ed25519 can be described as a scheme.
Requires Node 22 or later, or Bun. No runtime dependencies; the cryptography is Web Crypto.
npm install fishhook-ant
import { Verifier, schemes, fromUtf8 } from "fishhook-ant";
import { verifyRequest } from "fishhook-ant/http";
const stripe = new Verifier({
scheme: schemes.stripe,
key: fromUtf8(process.env.STRIPE_WEBHOOK_SECRET!),
tolerance: 300,
rememberReplayKey: async (key) => (await redis.set(`hook:${key}`, "1", { NX: true, PX: 600_000 })) === "OK",
});
export async function POST(request: Request): Promise<Response> {
const { body } = await verifyRequest(stripe, request, { maxBodyBytes: 1_000_000 });
const event = JSON.parse(new TextDecoder().decode(body));
// ...
return new Response(null, { status: 204 });
}
A refused delivery throws a FishhookError whose code says why. Answer it with a 4xx and do not run the handler.
There are no defaults for the key, the tolerance or the replay store. Anything that loosens a check is named unsafe*, so grep -rnE "unsafe[A-Z]" . finds every loosened choice in a codebase:
unsafeTolerance: a timestamp window above 300 seconds.unsafeAcceptReplays: true: accept the same delivery every time it arrives.Not included:
rememberReplayKey.tolerance is refused for them and replays are caught only by rememberReplayKey. Keep those keys as long as you would act on a delivery at all.webhookTimestamp is inside the JSON body. Check it yourself after verification.fishhook-ant/http, which refuses a request whose body was already read.ISC.
Fishhook ants (Polyrhachis) carry hooked spines on their backs, and whatever grabs one gets hooked. This one exists because LLM-written tests against one of our projects sent replayed deliveries and deliveries with nonsense signatures, and the handlers accepted both.
Yes, the hooks look terribly drawn, I know. It looks like they added a plane tail to it.