Skip to content

Commit 97edc94

Browse files
refactor(webhooks): use 2-byte gzip magic per RFC 1952 (CHA-3071)
RFC 1952 defines the gzip magic number as the two-byte sequence 1F 8B; the third byte (CM) is informational and not part of the identifier. Trim the magic check from three bytes to two to match the spec and stay consistent with the reference implementations in the public docs. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3f48c0e commit 97edc94

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

stream_chat/webhook.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from stream_chat.base.exceptions import WebhookSignatureError
2525

26-
GZIP_MAGIC = b"\x1f\x8b\x08"
26+
GZIP_MAGIC = b"\x1f\x8b"
2727

2828
_BytesLike = Union[bytes, bytearray, memoryview, str]
2929

@@ -38,14 +38,14 @@ def _to_bytes(body: _BytesLike) -> bytes:
3838

3939
def ungzip_payload(body: _BytesLike) -> bytes:
4040
"""Return ``body`` unchanged unless it starts with the gzip magic
41-
(``1f 8b 08``), in which case the gzip stream is decompressed.
41+
(``1f 8b``, per RFC 1952), in which case the gzip stream is decompressed.
4242
4343
Magic-byte detection (rather than relying on a header) means the same
4444
handler stays correct when middleware - Rails, Django, Laravel, Phoenix -
4545
auto-decompresses the request before your code sees it.
4646
"""
4747
raw = _to_bytes(body)
48-
if raw[:3] != GZIP_MAGIC:
48+
if raw[:2] != GZIP_MAGIC:
4949
return raw
5050
try:
5151
return gzip.decompress(raw)

0 commit comments

Comments
 (0)