Repository navigation
Add semgrep rules for webhook handlers that skip signature verification - #2427
Merged
Merged
Conversation
Six rules in templates/semgrep-taint/webhook.yml flag Express/Koa, NestJS, Next.js, Flask, FastAPI, Django and Go net/http webhook handlers that read the request body and never verify the sender's signature. A handler clears only on crypto evidence (timingSafeEqual, compare_digest, hmac.Equal, subtle.ConstantTimeCompare, tsscmp, scmp, exact constructEvent names, ValidatePayload, or a verify call with a signature or raw-body argument) or on a verb-led name, decorator, Depends, UseGuards or DRF class that names a signature or hmac. Computing an HMAC and comparing it with === or == is still flagged. GET-only routes are skipped. This revision fixes two false positives. An outbound axios.post(SLACK_WEBHOOK_URL, ...) was treated as an inbound route; a route call now needs a function-literal handler. A svix receiver built in the handler and verified in a second step (wh = new Webhook(secret); wh.verify(payload, headers)) now clears in JS and Python. It also tightens and widens the rules in smaller ways: - sig counts only as its own word, so consignmentId and SIGNING_KEY no longer clear a handler. - verifyAndReceive, Twilio validateRequest/validate with a signature argument and slack is_valid_request now clear. - A flag read such as if (config.verifySignature), or a Python def of a signature verifier that is never called, no longer clears. - NestJS @put and @patch fire, and so do @Body("key") and @Body(pipe). A class-level @UseGuards naming a signature or hmac guard in any position clears both JS rules. - FastAPI Optional[Model] and Annotated[Model, Body()] parameters fire, and a GET api_route is skipped. - Go ServeHTTP on a webhook-named type fires. - The header documents the remaining known false positives and limits. Each change has a ruleid or ok fixture in scripts/test_semgrep_webhook.py. The new fixtures fail against the previous rules, and 29/29 mutants of the new patterns fail the suite. Tests: 1/1 (scripts/ci-tests.d/semgrep-webhook.sh, semgrep 1.183.0 live) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B4dfwdDQiF3RQMUqYBqefc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds six semgrep rules in
templates/semgrep-taint/webhook.yml. They flag webhook handlers that read the request body but never verify a signature. Covered frameworks: Express, NestJS, Next.js, Flask, FastAPI, Django and Go net/http.Why
An unverified webhook endpoint accepts forged events from anyone who finds the URL (CWE-345). No hub tool had a rule for this, so the class was unmapped.
Changes
templates/semgrep-taint/webhook.yml: 6 rules. A handler clears only on crypto evidence: a constant-time compare, a vendorconstructEvent/ValidatePayload/verify(call with a signature or raw-body argument, or a verb-led signature/hmac guard. Computing an HMAC and comparing it with===is still flagged.scripts/test_semgrep_webhook.py: annotated vulnerable, clean-twin and mutated fixtures. Tests assert the exact set of flagged handlers.scripts/ci-tests.d/semgrep-webhook.shandci.yml: wire the test into CI.changelog.d/semgrep-webhook-signature.md: rule list and known limits.Tests
1/1 suite (semgrep 1.183.0, live run). Size, fragments and privacy gates pass locally.
Known limits (follow-up)
The independent review returned SHIP with five 🟡 items, which will go into the next PR:
isValidSignature(andis_valid_signature(do not clear yet.ConstructEventWithToleranceand svixwh.Verify(payload, r.Header)are still flagged.new IncomingWebhook(..)followed by an unrelated.verify(clears.app.use('/webhooks', express.json({verify}))is flagged.🤖 Generated with Claude Code
https://claude.ai/code/session_01B4dfwdDQiF3RQMUqYBqefc