Stripe webhook handler does not verify the signature
Your Stripe webhook URL is public, so anyone can send it a request that looks like a Stripe event. If the handler trusts the body without checking the Stripe-Signature header, a forged checkout.session.completed can mark an order as paid or unlock a plan. The fix is to read the raw request body, pass it with the header and your endpoint's whsec_ secret to stripe.webhooks.constructEvent, and return a 400 when it throws. Parsing the body as JSON first changes the bytes and breaks the check, so verify before parsing.
The fix
export async function POST(req: Request) {
const event = await req.json();
if (event.type === "checkout.session.completed") {
await markOrderPaid(event.data.object.id);
}
return new Response("ok");
}import Stripe from "stripe";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function POST(req: Request) {
const body = await req.text();
const signature = req.headers.get("stripe-signature") ?? "";
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(body, signature, process.env.STRIPE_WEBHOOK_SECRET!);
} catch {
return new Response("Invalid signature", { status: 400 });
}
if (event.type === "checkout.session.completed") {
await markOrderPaid(event.data.object.id);
}
return new Response("ok");
}How ShipReady finds it
ShipReady looks at JavaScript, TypeScript and Python files whose path mentions stripe or webhook and that handle Stripe webhook events. A file with no constructEvent call and no stripe-signature reference is reported. Findings carry rule ID SR-PAY-001.
Run the check
npx @shipmate-agency/shipready check .# .github/workflows/shipready.yml
name: ShipReady
on: [push, pull_request]
permissions:
contents: read
security-events: write
jobs:
shipready:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: deeflect/shipready@v0.2.0Want a person to check every area and send the fixes as pull requests? Launch Lockdown, $950 once.