Skip to content

Add semgrep rules for webhook handlers that skip signature verification - #2427

Merged
remigiusz-antczak merged 2 commits into
mainfrom
lane/webhook-r7
Nov 18, 2026
Merged

remigiusz-antczak merged 2 commits into
mainfrom
lane/webhook-r7

Conversation

@remigiusz-antczak

Copy link
Copy Markdown
Collaborator

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 vendor constructEvent/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.sh and ci.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( and is_valid_signature( do not clear yet.
  • Go ConstructEventWithTolerance and svix wh.Verify(payload, r.Header) are still flagged.
  • new IncomingWebhook(..) followed by an unrelated .verify( clears.
  • app.use('/webhooks', express.json({verify})) is flagged.
  • The matrix row lands with the coverage-matrix PR.

🤖 Generated with Claude Code
https://claude.ai/code/session_01B4dfwdDQiF3RQMUqYBqefc

remigiusz-antczak and others added 2 commits November 18, 2026 12:32
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
@remigiusz-antczak
remigiusz-antczak merged commit 4f7f417 into main Nov 18, 2026
13 checks passed
@remigiusz-antczak
remigiusz-antczak deleted the lane/webhook-r7 branch November 18, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant