[security] Webhook helpers decompress gzip bodies with no size limit before checking the signature (gzip bomb)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Start with stream_chat/webhook.py, especially gunzip_payload and verify_and_parse_webhook, then inspect the webhook tests and the linked implementations for stream-py and stream-chat-js. Reproduce the oversized decompression case and trace how failures are reported. Done means decompression has a configurable output bound and oversized or invalid streams are rejected; the issue gives no test file or limit value.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I'm Claude Opus 5.5, AI can make mistakes. Written for a human user, who asked for this report.
Filed as a public issue tagged security, which SECURITY.md allows as an alternative to emailing [email protected].
Summary
verify_and_parse_webhook decompresses a gzip body completely before it checks X-Signature. The order is forced: the HMAC covers the uncompressed JSON. But gunzip_payload has no limit on how much it decompresses, so anyone who can reach a webhook endpoint can make it use hundreds of MB to GBs of memory with a small unsigned request, a classic "gzip bomb". A webhook endpoint has to be public for Stream to reach it, and the signature check only fails after the memory is already used.
Affected code
- stream-chat-python
stream_chat/webhook.py:gunzip_payloadcallsgzip.decompress(raw)with no limit, andverify_and_parse_webhookcalls it before_verify_and_parse.
https://github.com/GetStream/stream-chat-python/blob/24c93b2da80d9261047c8bf8bb19b46d34db612f/stream_chat/webhook.py#L44-L58 - stream-py (
getstream)getstream/webhook.py:gunzip_payloadcallsgzip.decompress(bytes(body)), used byverify_and_parse_webhook.
https://github.com/GetStream/stream-py/blob/f0f1da5661bd9a4ba131c5dd6e34f9c79151f987/getstream/webhook.py#L654-L678 - stream-chat-js
src/signing.ts:gunzipPayloadcallszlib.gunzipSync(body)withoutmaxOutputLength, used byverifyAndParseWebhook.
https://github.com/GetStream/stream-chat-js/blob/3c1a18a0be4d5086cce007b9e98ebab435bf386a/src/signing.ts#L162-L174
The SQS and SNS parsers (parse_sqs / parse_sns, parseSqs / parseSns) use the same helper. Their input normally comes from a queue we control, so the exposure there is lower.
Reproduction (stream-chat 4.32.0, Python 3.14)
import tracemalloc, zlib
from stream_chat.webhook import verify_and_parse_webhook
from stream_chat.base.exceptions import InvalidWebhookError
def bomb(size: int) -> bytes: # gzip of `size` zero bytes, built without holding `size` bytes
d = zlib.compressobj(9, zlib.DEFLATED, 31)
chunk = bytes(1 << 20)
return b"".join([d.compress(chunk) for _ in range(size >> 20)] + [d.flush()])
body = bomb(256 << 20) # 260,934 bytes on the wire
tracemalloc.start()
try:
verify_and_parse_webhook(body, "not-a-signature", "secret")
except InvalidWebhookError as e:
print(e) # "signature mismatch", raised only after inflating
print(tracemalloc.get_traced_memory()[1] >> 20, "MB peak") # 557 MB
A 255 KB unsigned request drives peak memory to ~558 MB before the signature is rejected. A ~1 MB request inflates to ~1 GB, and a handful of concurrent requests will run a typical container out of memory.
Suggested fix
Bound the output of decompression, and reject anything over the limit as an invalid webhook, so it can never succeed and costs at most the limit in memory:
- Python:
zlib.decompressobj(wbits=16 + zlib.MAX_WBITS).decompress(raw, max_length=LIMIT + 1). Treat output longer thanLIMITas an error, and check.eof(truncated stream) and.unused_data(trailing data). - Node:
zlib.gunzipSync(body, { maxOutputLength: LIMIT }), which throwsRangeErrorpast the limit. - The limit: a default sized well above any real event, overridable by callers. Stream already caps SQS messages at 256 KB, which may be a natural default. The recorded real chat webhook events we hold are 7–18 KB.
Documenting the limit in the webhook docs' compression section would also help people who decompress in their own middleware.
Context
We hit this while adding gzip support to our webhook receiver. We decompress through a capped zlib.decompressobj there instead of the SDK helper, and would happily switch back once the helper is bounded.
- Ngôn ngữ chính
- Python
- Star
- 73
- Fork
- 20
- Merge trung bình
- 11 giờ 34 phút
- Pull request đã merge (30 ngày)
- 7
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của GetStream/stream-chat-python
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
GetStream/stream-chat-python#252 ·
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
GetStream/stream-chat-python#167 · 5 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
GetStream/stream-chat-python#166 · 2 bình luận ·
-
conda?Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
GetStream/stream-chat-python#152 ·
-
Add a new way to query all usersĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
GetStream/stream-chat-python#151 ·
Tất cả issue của GetStream/stream-chat-python
Issue tương tự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
NatLabRockies/openstudio-mcp#286 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
intersystems/ipm#1338 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
separate_packages splits imports from the same explicitly configured packageCó thể đã có người làm @rahul05ranjan đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
The v0-through-v1 path derives ShutdownDuration its own way, silently overriding a user's definitionĐang mởv1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày