fix(api): apply baggage size and entry caps on extract#2164
Open
tonghuaroot wants to merge 1 commit into
Open
Conversation
The W3C Baggage TextMapPropagator declares three constants (MAX_ENTRIES=180, MAX_ENTRY_LENGTH=4096, MAX_TOTAL_LENGTH=8192) and the private 'encode' helper applies all three on the inject path. The 'extract' path walks the inbound header through 'gsub' and 'split' and iterates every entry with no corresponding gate, so the caps are asymmetric between the two directions. This change hoists the same policy into 'extract' so the two paths are consistent: - reject the header outright when its byte size exceeds MAX_TOTAL_LENGTH - skip any individual entry whose byte size exceeds MAX_ENTRY_LENGTH - stop iterating after MAX_ENTRIES decoded entries The loop body is factored into a private 'decode_entries' helper to keep 'extract' within the project's complexity budget. Three new tests cover each of the gates and mirror the existing inject-side limit tests. Signed-off-by: tonghuaroot <tonghuaroot@gmail.com>
xuan-cao-swi
approved these changes
May 27, 2026
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.
Fixes #2163.
Summary
OpenTelemetry::Baggage::Propagation::TextMapPropagatordeclares three private constants for the W3C Baggage spec limits (MAX_ENTRIES = 180,MAX_ENTRY_LENGTH = 4096,MAX_TOTAL_LENGTH = 8192). The privateencodehelper used on inject applies all three, and dedicated tests exist for each one. Theextractpath does not consult any of them, so the inject and extract directions enforce different rules.This PR hoists the existing inject-side policy into
extractso the two paths share the same rule, mirroring whatopentelemetry-go,opentelemetry-dotnet,opentelemetry-cpp, and recentopentelemetry-javaalready do on their inbound side.Changes
api/lib/opentelemetry/baggage/propagation/text_map_propagator.rb:extractreturns the original context if the header byte size exceedsMAX_TOTAL_LENGTH.decode_entrieshelper runs the loop:breakonceMAX_ENTRIESentries have been decodednextpast any entry whose byte size exceedsMAX_ENTRY_LENGTHextractwithin the project'sMetrics/CyclomaticComplexityandMetrics/PerceivedComplexitybudgets.api/test/opentelemetry/baggage/propagation/text_map_propagator_test.rb:describe 'limits mirroring #inject'block adds three tests that parallel the existing inject-side cap tests:returns the same context object when the header exceeds the total length of 8192 bytesenforces max of 180 entries on extractskips entries whose size exceeds the max entry length of 4096 bytesVerification
Notes
This change was originally submitted via the private advisory channel (
GHSA-g4r4-95p7-vp43, now closed) and the project responded that it is not considered a security vulnerability but is worth fixing, and asked for a standard issue + PR. The framing here is consistency between inject and extract, not security.The behavior change is conservative:
MAX_TOTAL_LENGTHbecomes a no-op (returns the original context, same as the existingnil/empty?short-circuit).MAX_ENTRY_LENGTHis skipped while other entries continue to decode, matching whatencodedoes on the inject side.MAX_ENTRIESstop being decoded, matching the existing inject-side behaviour.