Skip to content

Add max baggage length as limitation#8222

Open
XSAM wants to merge 25 commits intoopen-telemetry:mainfrom
XSAM:fix/baggage-parsing
Open

Add max baggage length as limitation#8222
XSAM wants to merge 25 commits intoopen-telemetry:mainfrom
XSAM:fix/baggage-parsing

Conversation

@XSAM
Copy link
Copy Markdown
Member

@XSAM XSAM commented Apr 17, 2026

goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/baggage
cpu: Apple M1 Max
                  │      old.txt      │               new.txt                │
                  │      sec/op       │   sec/op     vs base                 │
ParseOversized-10   23409245.5n ± 14%   133.2n ± 3%  -100.00% (p=0.000 n=10)

                  │    old.txt     │              new.txt               │
                  │      B/op      │    B/op     vs base                │
ParseOversized-10   801099.00 ± 0%   88.00 ± 0%  -99.99% (p=0.000 n=10)

                  │     old.txt     │               new.txt               │
                  │    allocs/op    │ allocs/op   vs base                 │
ParseOversized-10   250007.000 ± 0%   3.000 ± 0%  -100.00% (p=0.000 n=10)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 94.73684% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.9%. Comparing base (4086701) to head (c782fa6).

Files with missing lines Patch % Lines
propagation/baggage.go 93.3% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #8222   +/-   ##
=====================================
  Coverage   82.9%   82.9%           
=====================================
  Files        314     314           
  Lines      24985   25019   +34     
=====================================
+ Hits       20730   20760   +30     
- Misses      3882    3884    +2     
- Partials     373     375    +2     
Files with missing lines Coverage Δ
baggage/baggage.go 98.7% <100.0%> (-0.8%) ⬇️
propagation/baggage.go 94.0% <93.3%> (-1.0%) ⬇️

... and 1 file with indirect coverage changes

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

@XSAM XSAM marked this pull request as draft April 17, 2026 00:21
@XSAM XSAM marked this pull request as ready for review April 17, 2026 06:23
@pellared pellared requested a review from Copilot April 17, 2026 07:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds stricter enforcement of W3C Baggage size limits across parsing (baggage) and extraction (propagation), and reduces overhead/error verbosity for malformed inputs.

Changes:

  • Enforce an 8192-byte maximum baggage string size in baggage.Parse, and cap joined parse errors to a fixed maximum.
  • Add an aggregate byte budget guard when extracting from multiple baggage header values in the propagator.
  • Update/add tests and a benchmark to cover oversized inputs and aggregate-budget behavior, plus a changelog entry.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
propagation/baggage.go Adds aggregate byte budget limit when processing multiple baggage header values.
propagation/baggage_test.go Updates expectations for aggregate-budget behavior and adds new extraction tests.
baggage/baggage.go Adds max-size early rejection and caps how many parse errors are joined.
baggage/baggage_test.go Updates parse tests for new oversize behavior; adds benchmark and error-cap test.
CHANGELOG.md Adds a release note about the baggage parsing/extraction change.

Comment thread baggage/baggage.go
Comment thread propagation/baggage_test.go
Comment thread CHANGELOG.md Outdated
Comment thread propagation/baggage.go Outdated
Comment thread propagation/baggage.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread propagation/baggage.go Outdated
Comment thread propagation/baggage.go
Comment thread baggage/baggage.go Outdated
Copy link
Copy Markdown
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Thanks for tightening the aggregate-size handling here. I think there is one edge case left around repeated baggage headers where the combined wire value can still exceed the intended limit. I left an inline note on the specific check with the concrete case and the adjustment that should make the enforcement consistent.

Comment thread propagation/baggage.go
Comment thread propagation/baggage.go Outdated
@MrAlias MrAlias added this to the v1.44.0 milestone Apr 23, 2026
XSAM and others added 2 commits April 28, 2026 13:58
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@XSAM XSAM force-pushed the fix/baggage-parsing branch from 285423e to 55e5b4f Compare April 28, 2026 21:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread propagation/baggage.go
Comment thread propagation/baggage_test.go Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread CHANGELOG.md Outdated
@pellared
Copy link
Copy Markdown
Member

pellared commented Apr 29, 2026

Can you add both benchmark and benchstat results to the PR description?

Comment thread baggage/baggage_test.go Outdated
Comment thread propagation/baggage.go Outdated
Comment thread propagation/baggage.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread propagation/baggage.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Comment thread propagation/baggage.go
Comment on lines +88 to +90
if totalBytes > maxBytesPerBaggageString {
parseErrors++
if parseErrors <= maxParseErrors {
Comment thread propagation/baggage.go
Comment on lines 127 to +129
b, err := baggage.New(members...)
if err != nil {
errorhandler.GetErrorHandler().Handle(err)
truncateErr = errors.Join(truncateErr, err)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Loading additional members after the whole header has exceeded the limit requires more memory allocation. I think this is a trade-off: our last-one-wins is a best-effort promise when facing oversized baggage.

Comment thread baggage/baggage.go
Comment on lines +500 to +504
// If the raw baggage-string exceeds the maximum allowed bytes (8192), an
// empty Baggage and an error are returned. If adding valid members would
// cause the parsed baggage to exceed the maximum allowed bytes (8192), or if
// the baggage-string exceeds the maximum allowed members (64), parsing stops
// and an error is returned along with the partial result.
Comment thread baggage/baggage.go
Comment thread propagation/baggage.go
Comment on lines +105 to +112
if uw, ok := err.(interface{ Unwrap() []error }); ok {
parseErrors += len(uw.Unwrap())
} else {
parseErrors++
}
if parseErrors <= maxParseErrors {
truncateErr = errors.Join(truncateErr, err)
}
Copy link
Copy Markdown
Member

@pellared pellared May 5, 2026

Choose a reason for hiding this comment

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

If one header value returns a capped joined error from baggage.Parse, extractMultiBaggage counts len(Unwrap()) and may drop that error entirely once it crosses maxParseErrors, then only emits and 1 more error(s).

The existing propagation test covers many invalid headers, not one header with many invalid members.

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.

5 participants