opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

Fix baggage parsing for invalid percent-encoded members

Open Vcode2407 opened this issue 5 months ago • 3 comments

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 avatar Jun 16 '26 15:06 Vcode2407

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 90.94%. Comparing base (a5cd87f) to head (f092d09). :warning: Report is 26 commits behind head on main.

Additional details and impacted files
@@              Coverage Diff              @@
##               main    #8480       +/-   ##
=============================================
+ Coverage     78.54%   90.94%   +12.40%     
- Complexity     8468    10211     +1743     
=============================================
  Files          1008     1013        +5     
  Lines         28824    27180     -1644     
  Branches       3569     3184      -385     
=============================================
+ Hits          22639    24719     +2080     
+ Misses         5342     1735     -3607     
+ Partials        843      726      -117     

:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Jun 16 '26 16:06 codecov[bot]

@Vcode2407 I want to echo @psx95's question:

Thanks for the PR. Was there a related issue reported about this that you came across?

Java's current implementation is: if anything in baggage is inproperly encoded, drop everything. I think this is a fine stance to take and doesn't violate any spec required behavior.

If there's a known instance where a stable, widely used baggage injector has a bug where it improperly encodes, then we might want to rethink this stance to be more flexible. But if its just the case that a one-off internal baggage injector did something wrong, I don't think its strictly a good thing to be more accommodating since being more accommodating obscures a bug in the injector code.

jack-berg avatar Jun 22 '26 19:06 jack-berg

@jack-berg Thanks for the follow-up.

I didn't come across a specific issue report, and this wasn't motivated by the Go or JS implementations. While looking through the baggage parsing flow, I noticed that a single invalid percent-encoded member caused the remaining valid members in the same header to be discarded. My thought was that preserving valid members while skipping only the malformed entry could make the parser more tolerant of malformed input.

That said, I understand the concern that being more permissive could obscure bugs in baggage injectors, and I agree that's an important tradeoff to consider.

Vcode2407 avatar Jun 23 '26 05:06 Vcode2407

Thank you for your contribution @Vcode2407! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

otelbot[bot] avatar Jun 25 '26 20:06 otelbot[bot]