Skip to content

Fix/baggage propagator outbound limits#5163

Merged
lzchen merged 12 commits intoopen-telemetry:mainfrom
lzchen:fix/baggage-propagator-outbound-limits
May 5, 2026
Merged

Fix/baggage propagator outbound limits#5163
lzchen merged 12 commits intoopen-telemetry:mainfrom
lzchen:fix/baggage-propagator-outbound-limits

Conversation

@lzchen
Copy link
Copy Markdown
Contributor

@lzchen lzchen commented Apr 29, 2026

Address size limits for inject outbound calls in baggage. I refactored out length + validation logic out since we are using it for both extract and inject now. One behavioral breaking change is that previously, only VALID entries in extract counted towards the 180 limit but I believe we should count ALL entries so attackers won't be able to fill the header with a bunch of invalid entries. The spec is unclear about this.

lzchen and others added 2 commits April 29, 2026 12:26
Assisted-by: Claude Opus 4.6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Assisted-by: Claude Opus 4.6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lzchen lzchen requested a review from a team as a code owner April 29, 2026 16:46
lzchen and others added 2 commits April 29, 2026 12:48
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py
Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py Outdated
Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py Outdated
The _apply_baggage_limits helper already logs a warning when the
maximum number of list-members is exceeded, making the early check
redundant.

Assisted-by: Claude Opus 4.6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py Outdated
Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py
Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py Outdated
Copy link
Copy Markdown
Contributor

@ocelotl ocelotl left a comment

Choose a reason for hiding this comment

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

Just a few comments/questions ✌️

Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py Outdated
Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py Outdated
Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py Outdated
Copy link
Copy Markdown

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

This PR enforces W3C Baggage outbound size limits in W3CBaggagePropagator.inject() and refactors limit enforcement into a shared helper used by both extraction and injection to consistently cap header size, pair size, and number of members.

Changes:

  • Add shared _apply_baggage_limits() helper and use it in both extract() and inject().
  • Enforce outbound inject limits (max pairs, max list-member length, max header length) and avoid injecting an empty baggage header when everything is dropped.
  • Update/add tests and document the behavior change in the changelog (extract counting behavior).

Reviewed changes

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

File Description
opentelemetry-api/src/opentelemetry/baggage/propagation/init.py Adds shared size-limit helper; applies limits in extract() and inject(); refactors encoding helper.
opentelemetry-api/tests/propagators/test_w3cbaggagepropagator.py Updates extraction log expectations; adds new injection limit tests; adjusts fields test mocking.
opentelemetry-api/tests/propagators/test__envcarrier.py Updates fields test mocking to align with new injection implementation.
CHANGELOG.md Notes outbound enforcement and extract counting behavior change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py Outdated
Comment thread opentelemetry-api/tests/propagators/test_w3cbaggagepropagator.py
lzchen and others added 4 commits April 30, 2026 10:00
…__.py

Co-authored-by: Lukas Hering <40302054+herin049@users.noreply.github.com>
Enforce header value and total size limits when injecting baggage
entries per the W3C Baggage specification.

Assisted-by: Claude Opus 4.6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Assisted-by: Claude Opus 4.6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py Outdated
Assisted-by: Claude Opus 4.6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py
Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py
@lzchen lzchen merged commit dd92fc1 into open-telemetry:main May 5, 2026
464 checks passed
@lzchen lzchen deleted the fix/baggage-propagator-outbound-limits branch May 5, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants