Bound gzip decompression in ingest to prevent decompression-bomb DoS - #3
Merged
VasiliyRad merged 1 commit intoJul 24, 2026
Merged
Conversation
/v1/ingest decompressed Content-Encoding: gzip bodies with a single gzip.decompress() call, which fully materializes the output before any size check runs. A holder of a valid ingest token could send a small, highly-compressible payload (~1000:1 ratio is trivial with gzip) that expands to gigabytes in memory before the existing post-decompression size check ever fires. Replace it with _gunzip_bounded, which decompresses via zlib.decompressobj(...).decompress(data, max_length=...) and aborts (413) as soon as running output exceeds the configured limit, so peak memory stays close to the limit regardless of the true decompressed size. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Collaborator
Author
|
@calebjohn24, @jalexray, can you take a look? Can you add me as a contributor to the repo? |
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
/v1/ingestdecompressedContent-Encoding: gzipbodies with a singlegzip.decompress()call, which fully materializes the output before any size check runs. A holder of a valid ingest token could send a small, highly-compressible payload (~1000:1 ratio is trivial with gzip) that expands to gigabytes in memory, pastMG_MAX_BODY_BYTES, before the existing post-decompression size check ever fires — a cheap way to OOM the server for every integration sharing that token._gunzip_bounded, which decompresses viazlib.decompressobj(...).decompress(data, max_length=...)and aborts (413) as soon as running output exceeds the configured limit, so peak memory stays close to the limit regardless of the true decompressed size.MG_MAX_BODY_BYTESbefore this change (just enforced too late) — this PR does not introduce a new limit, only enforces the existing one earlier.Test plan
server/tests/test_gunzip_bounded.py: happy-path round-trip, exact-boundary (limit vs. limit+1), a payload spanning multiple internal decompression rounds (regression guard for anunconsumed_tailhandling bug caught during review of my own first draft), a real ~1000:1 decompression bomb rejected without full expansion, and malformed-gzip handling.test_gzip_ingestend-to-end round-trip) passes locally against Postgres 14 — no regressions to legitimate gzip ingest traffic.🤖 Generated with Claude Code