fix(protocol): cap decompressed payload size to prevent gzip bombs (#942) - #943
Merged
Merged
Conversation
Message.Decode decompressed gzip/snappy payloads with io.ReadAll and no output cap, before service lookup or auth. MaxMessageLength only bounds the compressed wire length, so a small frame could expand to gigabytes and OOM the server pre-authentication (issue #942). - util: add UnzipLimited using io.LimitReader to bound output; Unzip honors package-level MaxDecompressedSize (default 0 = unlimited). - protocol: add optional LimitedUnzipper interface, implement on Gzip and Snappy compressors; Decode caps output via MaxDecompressedLength. - server: add WithMaxDecompressedLength / WithMaxMessageLength options. Defaults stay unlimited for backward compatibility. Fixes #942
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
Fixes #942 โ an unauthenticated gzip decompression bomb in the rpcx wire protocol.
Message.Decodedecompressed gzip (and snappy) payloads withio.ReadAlland no cap on output size, before service lookup or auth.MaxMessageLengthonly bounds the compressed wire length, so a small frame (<2MB) could expand to gigabytes and OOM the server fully pre-authentication.Changes
UnzipLimited(data, maxSize)usingio.LimitReader(gr, maxSize+1)to detect overflow without allocating the oversized payload; returns newErrDecompressedSizeTooLarge.Unzipnow honors package-levelMaxDecompressedSize.LimitedUnzipperinterface, implemented onGzipCompressorandSnappyCompressor(snappy had the same unboundedio.ReadAll).MaxDecompressedLength;Decodecaps decompression viaLimitedUnzipperwhen set โ bounded before service lookup and auth.WithMaxDecompressedLength(int64)andWithMaxMessageLength(int)options.Backward compatibility
Caps default to
0(unlimited), so behavior is unchanged unless configured. Servers accepting untrusted traffic should set one, e.g.:Tests
util.TestUnzipLimitedโ payload over/at/under the cap.protocol.TestDecodeDecompressBombโ a small compressed frame expanding to 1 MiB is rejected when the cap is set, decodes fine when unlimited.All of
./util,./protocol,./serverbuild, vet, and test green.