Skip to content

baggage: Replace invalid UTF-8 during extraction - #4751

Open
Amanpal9 wants to merge 1 commit into
open-telemetry:mainfrom
Amanpal9:fix-baggage-invalid-utf8
Open

Amanpal9 wants to merge 1 commit into
open-telemetry:mainfrom
Amanpal9:fix-baggage-invalid-utf8

Conversation

@Amanpal9

Copy link
Copy Markdown

Summary

  • Replace malformed UTF-8 octets in percent-decoded baggage values with U+FFFD.
  • Preserve valid UTF-8 values and continue rejecting decoded ASCII control bytes.
  • Add regression coverage for malformed and valid encoded sequences.

Closes #4748.

Validation

  • Compiled and ran a standalone C++11 smoke program against the updated header for invalid UTF-8 replacement, valid UTF-8 preservation, header encoding, and control-byte rejection.
  • The full CMake/gtest suite could not be run because CMake and the repository's GoogleTest dependencies are unavailable in this environment.

@Amanpal9
Amanpal9 requested a review from a team as a code owner October 30, 2026 15:47

@marcalff marcalff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the patch.

See comments

bool err = false;
auto key_str = UrlDecode(common::StringUtil::Trim(key), err);
auto value_str = UrlDecode(common::StringUtil::Trim(value), err);
value_str = ReplaceInvalidUtf8(value_str);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In my understanding of the w3c baggage spec, the code should:

  • trim whitespace, only SPACE and HTAB
  • check for key and value validity
  • URL Decode
  • Replace invalid UTF8

all this in that order.

This branch has not been deployed

No deployments
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.

Baggage::FromHeader drops entries whose percent-decoded value is not valid UTF-8, instead of substituting U+FFFD

2 participants