Repository navigation
Conversation
gunzip_payload runs before the signature check, so an unsigned gzip bomb could exhaust memory. Decompression now stops at MAX_WEBHOOK_PAYLOAD_BYTES (default 10 MiB) and raises InvalidWebhookError. Corrupt deflate data now raises InvalidWebhookError instead of zlib.error.
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.
Submit a pull request
CLA
Description of the pull request
Problem
gunzip_payloadinflated a gzip body with no size limit before the signature check, so an unsigned request of a few hundred KB could expand to hundreds of MB and exhaust memory on a webhook endpoint.Solution
Decompression now stops at 10 MiB and raises
InvalidWebhookError("gzip decompression failed: payload exceeds 10485760 bytes"). The same helper backsverify_and_parse_webhook,parse_sqsandparse_sns. Raise the cap if your events are larger:Uncompressed bodies are not limited, and multi-member gzip still inflates as before. Corrupt deflate data now raises
InvalidWebhookErrorinstead of leakingzlib.error. This matches the default and error message of the other server SDKs.How to verify
pytest stream_chat/tests/test_webhook_compression.py(passes locally on Python 3.8 and 3.12).verify_and_parse_webhookandparse_sqs, and honour a custom limit.Note
Medium Risk
Touches security-sensitive webhook ingestion (decompression runs before signature verification); behavior change rejects oversized gzip payloads that previously might have exhausted memory.
Overview
Adds a decompression size cap on webhook gzip handling so a small compressed body cannot expand without bound before HMAC verification.
gunzip_payloadnow reads throughgzip.GzipFilewith a 10 MiB ceiling (MAX_WEBHOOK_PAYLOAD_BYTES, overridable onstream_chat.webhook). Payloads that decompress larger raiseInvalidWebhookErrorwith a clear “payload exceeds … bytes” message—the same path used byverify_and_parse_webhook,parse_sqs, andparse_sns. Malformed deflate is surfaced asInvalidWebhookErrorinstead of rawzlib.error.Tests cover corrupt gzip, multi-member streams, exact-limit success, gzip-bomb rejection before signature checks, and a tunable limit via
monkeypatch.Reviewed by Cursor Bugbot for commit 1e51067. Bugbot is set up for automated code reviews on this repo. Configure here.