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
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
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 "", 200What Skylos leaves alone
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 "", 200Why 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
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
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
- Runs with
--danger. Python files intest,tests,fixtureorfixturesfolders,test_*.pyand*_test.pyare skipped. - Python: looks at each function. The file path, function name, route path or code must contain
webhookand name a provider (stripe,github,clerk,svix,shopify,supabase,resend,twilio,slack,discord,linear,vercel,netlify,paddle,lemonsqueezy). - Python: the function must handle
POST(a.post()decorator,route(..., methods=["POST"])or arequest.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 asconstruct_event(,verify_signature(,verify_webhook(,validate_signature(,hmac.compare_digest(,hmac.new(or aWebhook(...)object's.verify(. This is a text match. - TypeScript and JavaScript: finds
POSTroutes (Next.js route files, Express, Fastify, Hono) whose path names a webhook and a provider, or a provider event path in a file that importsstripe,svix,@octokit/webhooksorcrypto, and that read the request body. - TypeScript and JavaScript are stricter: the route is safe only when a verifier from the real package (Stripe
constructEvent, svixWebhook.verify, Octokitverify) or acrypto.timingSafeEqualHMAC 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.
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 "", 200When 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 withrequest.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
defline 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--baselineaccept the handlers you have and report only new ones.