fishhook-ant - v0.1.0
    Preparing search index...

    fishhook-ant - v0.1.0

    fishhook-ant

    Fishhook ant logo

    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:

    • Remembering replay keys. That is your store, behind rememberReplayKey.
    • Running a handler once when the sender retries an event. Use mycocepurus-smithii.
    • Out-of-order events and deleted entities coming back. Use burying-beetle.
    • Twilio, SendGrid, AWS SNS, and plain shared-secret headers (Telegram, GitLab's secret token). guides/boundaries.md says why and where each goes.
    • GitHub, Shopify and Linear sign no timestamp, so 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.
    • Linear's webhookTimestamp is inside the JSON body. Check it yourself after verification.
    • Frameworks that parse JSON before your route runs change the bytes, and the signature fails. Read the raw body, or use fishhook-ant/http, which refuses a request whose body was already read.
    • The presets follow each provider's documentation as of November 2026 and have not yet been checked against a real captured delivery from every provider.

    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.