Skip to content

[config/confighttp, config/configgrpc] Bound the zstd decoder window by the server's size limit - #16281

Merged
codeboten merged 6 commits into
open-telemetry:mainfrom
honeycombio:zstd-bounded-decode-window
Nov 4, 2026
Merged

codeboten merged 6 commits into
open-telemetry:mainfrom
honeycombio:zstd-bounded-decode-window

Conversation

@lizthegrey

@lizthegrey lizthegrey commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

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_size or max_recv_msg_size_mib applies, 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 from max_recv_msg_size_mib via zstd.SetMaxRecvMsgSize. Neither bound goes below 8 MiB, the largest window a default-configured encoder declares, so frames from default encoders keep decoding. decoderWrapper also implements io.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 -race passes for config/confighttp and config/configgrpc, golangci-lint is clean for both modules, and make chlog-validate passes.

Documentation

No configuration or API changes for users, so no documentation update.

Authorship

  • I, a human, wrote this pull request description myself.

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
@lizthegrey
lizthegrey requested a review from a team as a code owner November 1, 2026 10:18
@lizthegrey
lizthegrey requested a review from codeboten November 1, 2026 10:18
@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.34%. Comparing base (d8615c9) to head (36f70da).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jmacd jmacd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 codeboten left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment, otherwise i think this makes sense

Comment thread config/confighttp/compression.go Resolved
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
@codspeed

codspeed Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

✅ 5 untouched benchmarks
⏩ 9 skipped benchmarks1
🗄️ 2 archived benchmarks run2


Comparing honeycombio:zstd-bounded-decode-window (02ed941) with main (57b63bc)3

Open in CodSpeed

Footnotes

  1. 9 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. 2 benchmarks were run, but are now archived. If they were deleted in another branch, consider rebasing to remove them from the report. Instead if they were added back, click here to restore them. ↩

  3. No successful run was found on main (d8615c9) during the generation of this report, so 57b63bc was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@lizthegrey

Copy link
Copy Markdown
Member Author

Clamped to zstd.MaxWindowSize and documented the WithGrpcServerOption caveat in configgrpc/README.md in 627f921

@codeboten codeboten left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick updates 👍🏻

@lizthegrey

Copy link
Copy Markdown
Member Author

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
@codeboten
codeboten enabled auto-merge November 3, 2026 23:07
@codeboten
codeboten added this pull request to the merge queue Nov 3, 2026
Merged via the queue into open-telemetry:main with commit 2583302 Nov 4, 2026
72 of 73 checks passed
@github-actions github-actions Bot added this to the next release milestone Nov 4, 2026
gimsesu added a commit to gimsesu/opentelemetry-collector that referenced this pull request Nov 4, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[confighttp][configgrpc] zstd decompression allows unbounded memory allocation

4 participants