Repository navigation
[config/confighttp, config/configgrpc] Bound the zstd decoder window by the server's size limit - #16281
Conversation
A zstd frame header declares the window the decoder allocates before it produces any output, and the library default allows windows up to 512MiB. Both collector decompression paths accepted such frames: the HTTP Content-Encoding: zstd handler, which defaultCompressionAlgorithms enables on every server, and the gRPC zstd compressor registered in init(). Bound the window by what each server already accepts: - HTTP derives it from MaxRequestBodySize. - gRPC derives it from MaxRecvMsgSize through zstd.SetMaxRecvMsgSize, which configgrpc calls from getGrpcServerOptions. The bound is process-wide and only grows, because the gRPC compressor registry is global. Neither bound goes below 8MiB, the largest window a default-configured klauspost/compress encoder declares, so frames from default encoders keep decoding when a server is configured with a smaller limit. decoderWrapper now implements io.Closer, so grpc-go returns the decoder to its pool as soon as it is done with a message instead of leaving it to the finalizer. Assisted-by: Amp
Assisted-by: Amp
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16281 +/- ##
=======================================
Coverage 91.34% 91.34%
=======================================
Files 760 760
Lines 50569 50615 +46
=======================================
+ Hits 46190 46233 +43
- Misses 3029 3031 +2
- Partials 1350 1351 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jmacd
left a comment
There was a problem hiding this comment.
As workarounds go, this is pretty good. It doesn't help with the fact that we are decompressing before authorizing, but it helps.
Callers of WithGrpcServerOption(grpc.MaxRecvMsgSize(x)) will be broken; I think that's OK and there aren't any such callers that I know of, but it's worth documenting.
codeboten
left a comment
There was a problem hiding this comment.
Just one comment, otherwise i think this makes sense
Assisted-by: Amp
Clamp the decoder window to zstd.MaxWindowSize so configuring a larger message or body size cannot make the decoder allocate more than the library allows by default. Document that the bound follows max_recv_msg_size_mib and max_request_body_size, and that WithGrpcServerOption(grpc.MaxRecvMsgSize(x)) does not raise it. Assisted-by: Amp
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
|
Clamped to |
codeboten
left a comment
There was a problem hiding this comment.
Thanks for the quick updates 👍🏻
thank my AI assistant ;) seriously cheers for the reviews; we'll get this buttoned down and remediated right fast. |
specification/protocol/otlp.md is now a redirect stub, so its #protocol-details anchor no longer resolves and check-links fails for this file. Point at the exporter page, which is where the compression requirements live now. Assisted-by: Amp
2583302
…ntry The type change in metadata.yaml renamed the chloggen component from pkg/config/configgrpc to pkg/configgrpc. The entry from open-telemetry#16281 still used the old name, so chlog-validate failed after merging main. Assisted-by: Claude Opus 5.5
Description
Small degenerate zstd payloads can cause disproportionate memory allocation, resulting in denial of service when zstd compression is used in the OTLP grpc and http receivers.
The decoder allocates the window a frame declares before it produces any output, and the library default permits windows up to 512 MiB. Both collector decompression paths let a request drive that allocation before
max_request_body_sizeormax_recv_msg_size_mibapplies, because those bound the decoded output, not the window. On gRPC the message is decompressed in the transport ahead of any interceptor, so a receiver that requires a header still allocates for a request it will reject.This bounds the window by what each server already accepts: HTTP derives it from
max_request_body_size, gRPC frommax_recv_msg_size_mibviazstd.SetMaxRecvMsgSize. Neither bound goes below 8 MiB, the largest window a default-configured encoder declares, so frames from default encoders keep decoding.decoderWrapperalso implementsio.Closer, so gRPC returns a decoder to its pool as soon as it is done with a message instead of leaving it to the finalizer.Link to tracking issue
Fixes #16280; related to open-telemetry/opentelemetry-specification#5321 and Honeycomb internal issue SECENG-963
Testing
New tests in both packages: a crafted frame declaring a 512 MiB window is rejected with bounded allocation, a payload from a default-configured encoder still decodes, and an early-stopped gRPC read releases its decoder. Both rejection tests fail without the fix.
go test -racepasses forconfig/confighttpandconfig/configgrpc,golangci-lintis clean for both modules, andmake chlog-validatepasses.Documentation
No configuration or API changes for users, so no documentation update.
Authorship