Skip to content

Fix baggage parsing for invalid percent-encoded members#8480

Open
Vcode2407 wants to merge 1 commit into
open-telemetry:mainfrom
Vcode2407:fix-baggage-invalid-percent-encoding
Open

Fix baggage parsing for invalid percent-encoded members#8480
Vcode2407 wants to merge 1 commit into
open-telemetry:mainfrom
Vcode2407:fix-baggage-invalid-percent-encoding

Conversation

@Vcode2407

Copy link
Copy Markdown
Contributor

Description

Currently, an invalid percent-encoded baggage member can cause parsing of the remaining members in the same baggage header to abort.

For example:

baggage: key1=value1,bad=va%lue,key2=value2

When parsing bad=va%lue, percent decoding throws an IllegalArgumentException, preventing subsequent valid members from being processed.

This change skips only the invalid member and continues processing the remaining members in the header.

A regression test has been added to verify that valid members are preserved when another member contains invalid percent encoding.

Testing

./gradlew :api:all:test --tests io.opentelemetry.api.baggage.propagation.W3CBaggagePropagatorTest

@Vcode2407 Vcode2407 requested a review from a team as a code owner June 16, 2026 15:14
@Vcode2407 Vcode2407 force-pushed the fix-baggage-invalid-percent-encoding branch from 90736f6 to f8d2245 Compare June 16, 2026 16:13
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.53%. Comparing base (a5cd87f) to head (12bf01b).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8480      +/-   ##
============================================
- Coverage     78.54%   78.53%   -0.01%     
- Complexity     8468     8473       +5     
============================================
  Files          1008     1008              
  Lines         28824    28833       +9     
  Branches       3569     3570       +1     
============================================
+ Hits          22639    22644       +5     
- Misses         5342     5343       +1     
- Partials        843      846       +3     

☔ 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.

@psx95 psx95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR. Was there a related issue reported about this that you came across?
Or was this change motivated by the existing Go and JS implementations?

decodedValue = decodeValue(value);
metadataValue = decodeValue(metadataValue);
} catch (IllegalArgumentException e) {
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could be good to log a warning here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I looked into this, but left it unchanged since the current parsing behavior appears to favor ignoring invalid baggage and continuing. Happy to update this if logging is preferred.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't the current parsing behavior to throw an exception on invalid baggage?

IMO adding a warning level log about invalid baggage fields makes sense here - that will still let the program continue, but will inform the user that there probably is some invalid encoding in the baggage data.

@Vcode2407 Vcode2407 force-pushed the fix-baggage-invalid-percent-encoding branch from f8d2245 to 12bf01b Compare June 17, 2026 03:52
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.

2 participants