- Home
- Skills
- Frontend & Web Apps
- Webhook HMAC Gate
Webhook HMAC Gate
Verify Stripe, GitHub, Clerk, and Svix webhooks before any side effect ships.
$9
Works with the AI Agents you already use
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.
- Webhook inventory
- Path:
/api/stripe - Provider: Stripe
- Events handled:
checkout.session.completed - Side effects: Database fulfillment, User status update
- 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.
- 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 });
}
- Residual risks
- Secret Rotation: Ensure
STRIPE_WEBHOOK_SECRETis 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_SECRETto your.env.localand production environment. - Create the
webhookEventtable 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.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Frontend & Web Apps.
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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
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