Webhook HMAC Gate

    0

    Verify Stripe, GitHub, Clerk, and Svix webhooks before any side effect ships.

    $9

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Webhook HMAC Gate

    Example session with this skill installed

    Audit my Stripe webhook handler in app/api/stripe/route.ts and fix any security issues.

    • Read your context and instructions
    • Compiled the webhook hmac gate

    I have audited the webhook handler at app/api/stripe/route.ts. The implementation was consuming the JSON body before verification, which would cause signature failures, and lacked idempotency checks.

    1. Webhook inventory
    • Path: /api/stripe
    • Provider: Stripe
    • Events handled: checkout.session.completed
    • Side effects: Database fulfillment, User status update
    1. Gate findings
    • Severity: blocker

    Evidence: The code calls await req.json() at line 12. Stripe signatures require the exact raw bytes; re-serializing the object will cause verification to fail for many payloads.

    1. Hardening patch
    import { headers } from "next/headers";
    import { NextResponse } from "next/server";
    import Stripe from "stripe";
    import { db } from "@/lib/db";
    
    export const runtime = "nodejs";
    
    const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
      apiVersion: "2024-11-20.acacia",
    });
    
    export async function POST(req: Request) {
      const signature = (await headers()).get("stripe-signature");
      if (!signature) {
        return NextResponse.json({ error: "missing_signature" }, { status: 400 });
      }
    
      const rawBody = await req.text();
      let event: Stripe.Event;
      try {
        event = stripe.webhooks.constructEvent(
          rawBody,
          signature,
          process.env.STRIPE_WEBHOOK_SECRET!,
        );
      } catch {
        return NextResponse.json({ error: "invalid_signature" }, { status: 400 });
      }
    
      const seen = await db.webhookEvent.findUnique({ where: { id: event.id } });
      if (seen) {
        return NextResponse.json({ ok: true, duplicate: true });
      }
    
      await db.webhookEvent.create({
        data: { id: event.id, type: event.type },
      });
    
      if (event.type === "checkout.session.completed") {
        // Perform fulfillment side effects here
      }
    
      return NextResponse.json({ ok: true });
    }
    
    1. Residual risks
    • Secret Rotation: Ensure STRIPE_WEBHOOK_SECRET is rotated if logs were previously leaked.
    • Async Workers: For high-volume events, move fulfillment to a background queue after the idempotency check.

    Next steps

    • Add STRIPE_WEBHOOK_SECRET to your .env.local and production environment.
    • Create the webhookEvent table in your Prisma/DB schema to support idempotency.
    • Test the endpoint using the Stripe CLI to confirm signature match.

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

    About this skill

    Verify Stripe, GitHub, Clerk, and Svix webhooks before any side effect ships. Audits App Router webhook route handlers for missing HMAC/signature checks, raw-body mistakes, secret mishandling, replay gaps, and duplicate fulfillment. Returns Webhook inventory, Gate findings, Hardening patch, and Residual risks. Includes checklist, patterns, anti-patterns, and a bad-to-good Stripe example. Complements Server Action AuthZ for browser sessions; does not replace session auth.

    Cannot prove raw-body handling if framework abstractions hide the request stream. Requires server-side environment variables. Scope limited to Node.js/TypeScript environments.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 21 days ago

    Permissions

    Read Files
    Network Access
    Environment Variables
    Listed21 days ago

    What's inside

    Frequently Asked Questions

    This skill identifies and fixes security gaps in your API routes, specifically preventing 'forged' requests and replay attacks that can lead to data corruption or duplicate actions (like double-billing) by implementing industry-standard HMAC verification and idempotency logic.

    The skill is optimized for Next.js App Router environments using TypeScript and Node.js; it includes specialized logic to handle the 'raw body' stream requirements that often cause signature failures in standard Next.js route handlers.

    Yes, it includes pre-configured patterns for popular providers like Stripe, Clerk, GitHub, and Svix, ensuring that the generated patches use the correct SDK-specific verification methods and header names for each service.

    Unlike a basic prompt, this skill is engineered to avoid common AI pitfalls—such as suggesting 'req.json()' which breaks signature verification—and instead enforces byte-level integrity checks and constant-time comparisons required for production security.

    You receive the full agentic workflow for inventorying, auditing, and patching your routes, along with a suite of hardening templates designed for high-stakes environments where side-effect integrity is critical.

    New in Frontend & Web Apps