feat(client): max_decompressed_size guard against decompression bombs#1262
Open
quinnj wants to merge 2 commits into
Open
feat(client): max_decompressed_size guard against decompression bombs#1262quinnj wants to merge 2 commits into
quinnj wants to merge 2 commits into
Conversation
…n bombs Closes #1178. A new `max_decompressed_size` request keyword caps how many bytes an auto-decompressed (gzip/deflate) response body may produce; reading past it throws `DecompressionLimitError` before the bomb inflates. `0` (default) keeps the current unbounded behavior. The limiter wraps the decompressor stream, so it fires after at most one extra read chunk (memory stays bounded near the limit) and applies to both the materialized `resp.body` and caller-owned `response_stream` sinks. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1262 +/- ##
==========================================
- Coverage 84.36% 84.30% -0.07%
==========================================
Files 28 28
Lines 10689 10698 +9
==========================================
+ Hits 9018 9019 +1
- Misses 1671 1679 +8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…r type
The _DecompressLimitReader wrapper widened _response_body_reader's return into an
abstractly-parameterized union (Union{_BodyIO, _DecompressLimitReader,
TranscodingStream...}), which broke --trim static compilation
(trim_compile_tests verifier errors on macOS/Linux). Apply max_decompressed_size
inside the chunked read loops (_read_all_response_bytes / _copy_response_bytes!)
instead, leaving the reader's type set unchanged. Same DecompressionLimitError
and behavior; trim compile passes (63/63 locally).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Closes #1178.
Auto-decompression (gzip/deflate) currently has no size limit, so a small compressed payload can inflate to exhaust memory (a decompression/zip bomb). This adds an opt-in
max_decompressed_sizerequest keyword:0(default) keeps the current unbounded behavior — fully backward compatible.resp.bodyand caller-ownedresponse_streamsinks.HTTP.DecompressionLimitError(with the offendinglimit) for callers to catch.Tested with a ~4 MB-of-zeros gzip bomb (a few KB on the wire): rejected under a small limit, succeeds with no/large limit, and the limit is enforced on an
IOBuffersink too.Note: scoped to HTTP response-body decompression (the documented OOM vector). WebSocket frame limits are separate (
maxframesize, see #1181).🤖 Generated with Claude Code