Skip to main content

SKY-D282 · Security in code

Webhook handler trusts events without checking the signature

A webhook is a URL that a service such as Stripe, GitHub or Slack calls to tell your app that something happened, for example "this invoice was paid". The service signs each call with a shared secret. SKY-D282 reports a webhook handler that reads the event body without checking that signature first.

Languages
Python, TypeScript/JavaScript
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Catalog name
Webhook signature verification issue
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The webhook URL is public. Without the signature check, anyone can post a made-up "payment succeeded" event and get an order marked as paid, or fake a GitHub push to start a deployment.

What Skylos flags

app/webhooks.py · PythonReported on line 9
from flask import Flask, request from app.billing import mark_paid app = Flask(__name__)  @app.post("/stripe/webhook")def stripe_webhook():    event = request.get_json()    if event["type"] == "checkout.session.completed":        mark_paid(event["data"]["object"]["client_reference_id"])    return "", 200

What Skylos leaves alone

app/webhooks.py · Python
import os import stripefrom flask import Flask, abort, request from app.billing import mark_paid app = Flask(__name__)ENDPOINT_SECRET = os.environ["STRIPE_WEBHOOK_SECRET"]  @app.post("/stripe/webhook")def stripe_webhook():    signature = request.headers.get("Stripe-Signature", "")    try:        event = stripe.Webhook.construct_event(request.data, signature, ENDPOINT_SECRET)    except (ValueError, stripe.error.SignatureVerificationError):        abort(400)    if event["type"] == "checkout.session.completed":        mark_paid(event["data"]["object"]["client_reference_id"])    return "", 200

Why Skylos leaves it alone

The same Stripe route, but stripe.Webhook.construct_event() checks the raw body against the Stripe-Signature header and the secret, and a bad signature ends the request with 400 before the event is used.

More languages

TypeScript

Flagged

app/api/stripe/webhook/route.ts · TypeScriptReported on line 5
import { NextResponse } from "next/server"; import { markPaid } from "@/lib/billing"; export async function POST(request: Request) {  const event = await request.json();  if (event.type === "checkout.session.completed") {    await markPaid(event.data.object.client_reference_id);  }  return NextResponse.json({ received: true });}

Not flagged

app/api/stripe/webhook/route.ts · TypeScript
import { NextResponse } from "next/server";import Stripe from "stripe"; import { markPaid } from "@/lib/billing"; const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!); export async function POST(request: Request) {  const body = await request.text();  const signature = request.headers.get("stripe-signature");  let event;  try {    event = stripe.webhooks.constructEvent(      body,      signature,      process.env.STRIPE_WEBHOOK_SECRET,    );  } catch {    return NextResponse.json({ error: "Bad signature" }, { status: 400 });  }  if (event.type === "checkout.session.completed") {    await markPaid(event.data.object.client_reference_id);  }  return NextResponse.json({ received: true });}

Why Skylos leaves it alone

constructEvent comes from the real stripe package, receives the raw text body and the request's signature header, and a failure returns 400 before event is used.

How Skylos decides

  1. Runs with --danger. Python files in test, tests, fixture or fixtures folders, test_*.py and *_test.py are skipped.
  2. Python: looks at each function. The file path, function name, route path or code must contain webhook and name a provider (stripe, github, clerk, svix, shopify, supabase, resend, twilio, slack, discord, linear, vercel, netlify, paddle, lemonsqueezy).
  3. Python: the function must handle POST (a .post() decorator, route(..., methods=["POST"]) or a request.method == "POST" test) and read the body (request.get_json, request.json, request.data, request.body). It is reported unless its code contains a check such as construct_event(, verify_signature(, verify_webhook(, validate_signature(, hmac.compare_digest(, hmac.new( or a Webhook(...) object's .verify(. This is a text match.
  4. TypeScript and JavaScript: finds POST routes (Next.js route files, Express, Fastify, Hono) whose path names a webhook and a provider, or a provider event path in a file that imports stripe, svix, @octokit/webhooks or crypto, and that read the request body.
  5. TypeScript and JavaScript are stricter: the route is safe only when a verifier from the real package (Stripe constructEvent, svix Webhook.verify, Octokit verify) or a crypto.timingSafeEqual HMAC check gets the raw body and the request's signature before the body is used, and a failure stops the request.

How to fix it

Verify the signature on the raw request body with the provider's library, using the webhook secret from the environment, and reject the request when the check fails. Only then parse the event and act on it.

app/webhooks.py · Python · the fix, against the flagged file
Removed: from flask import Flask, requestAdded: import os Added: import stripeAdded: from flask import Flask, abort, requestAdded:  from app.billing import mark_paid app = Flask(__name__)Added: ENDPOINT_SECRET = os.environ["STRIPE_WEBHOOK_SECRET"]  @app.post("/stripe/webhook")def stripe_webhook():Removed:     event = request.get_json()Added:     signature = request.headers.get("Stripe-Signature", "")Added:     try:Added:         event = stripe.Webhook.construct_event(request.data, signature, ENDPOINT_SECRET)Added:     except (ValueError, stripe.error.SignatureVerificationError):Added:         abort(400)    if event["type"] == "checkout.session.completed":        mark_paid(event["data"]["object"]["client_reference_id"])    return "", 200

When it can be wrong

  • Python: verification done in a helper whose name is not in the list (for example check_stripe_event(request)) is not seen, so the handler is reported.
  • Python: missed when the handler only mentions a check, for example hmac.new(...) whose result is compared with == or never compared, and when the body is read with request.get_data().
  • TypeScript: a check written differently from the forms above is reported. Passing process.env.STRIPE_WEBHOOK_SECRET ?? "" as the secret is one case: the empty fallback is not accepted as a secret.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Mark the line of the finding (the def line in Python, the route line in TypeScript) and name what verifies the call.

    Python
    def stripe_webhook():  # skylos: ignore[SKY-D282] verified by StripeGuard middleware
  • [tool.skylos] ignore = ["SKY-D282"] turns the rule off for the whole project.

  • skylos baseline . and then --baseline accept the handlers you have and report only new ones.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.