fix(webhook): enforce body-size limit when Content-Length is absent - #672
Open
hashbender wants to merge 1 commit into
Open
fix(webhook): enforce body-size limit when Content-Length is absent#672hashbender wants to merge 1 commit into
hashbender wants to merge 1 commit into
Conversation
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.
Summary
The generic webhook adapter (
gateway/platforms/webhook.py) enforced its per-routemax_body_byteslimit only via theContent-Lengthheader:A request using
Transfer-Encoding: chunked(or a spoofed smallContent-Length) makesrequest.content_lengthNone, soNone or 0 == 0and the check is skipped entirely. The full body is then buffered into memory regardless of the route's configuredmax_body_bytes.This is reachable by an unauthenticated caller — the body must be read before HMAC signature verification — so it bypasses the documented size guard and is a DoS vector on an internet-exposed webhook endpoint. The module docstring even claims "Body size limits checked before reading payload", which chunked requests defeat.
The sibling adapters Feishu (
plugins/platforms/feishu/adapter.py) and WeCom already guard this exact case with a post-read length check and have regression tests forcontent_length=None— the generic adapter was the odd one out.Fix
len(raw_body) > self._max_body_bytes→ 413), keeping theContent-Lengthfast path.Content-LengthNone) with an over-limit body, asserting 413.Test plan
tests/gateway/test_webhook_adapter.py— 69 passed (68 existing + 1 new)test_webhook_adapter,test_webhook_signature_rate_limit,test_webhook_integration,test_webhook_dynamic_routes,test_webhook_deliver_only) — 103 passed202instead of413) and passes with itMirror-of: NousResearch#56829
NousResearch#56829