Repository navigation
Description
Description
System.Diagnostics.W3CPropagator stops parsing the baggage header when it encounters a malformed key=value shape. This drops later valid baggage members from the same header.
The current implementation in TryExtractBaggage breaks out of parsing when the current entry has no key/value separator or has the separator at the beginning/end:
int keyValueSeparator = currentEntry.IndexOf(Equal);
if (keyValueSeparator <= 0 || keyValueSeparator >= currentEntry.Length - 1)
{
break; // invalid format
}The W3C baggage specification defines a baggage-string as a list of list-members:
baggage-string = list-member 0*179( OWS "," OWS list-member )
list-member = key OWS "=" OWS value *( OWS ";" OWS property )Pinned w3c/baggage source snapshot: https://github.com/w3c/baggage/blob/2187a480c633d501b2f1ef42ced9f6837461d6ec/baggage/HTTP_HEADER_FORMAT.md
For malformed baggage strings, the W3C baggage editor draft does not prescribe a single parsing strategy. It allows implementations to remove an offending list-member before propagating the rest, or to choose another invalid-input policy. Continuing after a malformed member therefore appears to be a valid and more interoperable policy.
This came up while reviewing baggage behavior across four OpenTelemetry implementations. The OpenTelemetry implementations generally skip invalid members and continue parsing later valid members:
- OpenTelemetry Go: invalid members are skipped and a partial valid result is returned.
https://github.com/open-telemetry/opentelemetry-go/blob/a3de6477db56780c8a209488eb653fc1749da9ef/baggage/baggage.go - OpenTelemetry Java: parser sets
skipToNextfor an invalid member and resets at the next comma.
https://github.com/open-telemetry/opentelemetry-java/blob/327f56459843656015b87e044f6e79d4936927cb/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/Parser.java - OpenTelemetry Rust: extraction uses
filter_mapso invalid entries are ignored while later entries continue.
https://github.com/open-telemetry/opentelemetry-rust/blob/a0a9305dad889caa08ebfdae480470568d979d25/opentelemetry-sdk/src/propagation/baggage.rs - OpenTelemetry .NET: the reviewed pinned snapshot skips entries without
=and continues parsing later entries.
https://github.com/open-telemetry/opentelemetry-dotnet/blob/01b9df726f2e75aa4968074eb88241f396ca19f2/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs
Reproduction Steps
Extract baggage from a carrier containing one malformed member followed by a valid member:
baggage: valid1=value1,bad,valid2=value2Minimal code shape:
using System.Diagnostics;
var propagator = DistributedContextPropagator.CreateDefaultPropagator();
var carrier = new Dictionary<string, string>
{
["baggage"] = "valid1=value1,bad,valid2=value2",
};
var baggage = propagator.ExtractBaggage(
carrier,
static (object? carrier, string fieldName, out string? fieldValue, out IEnumerable<string>? fieldValues) =>
{
var headers = (Dictionary<string, string>)carrier!;
headers.TryGetValue(fieldName, out fieldValue);
fieldValues = null;
});
// Observe extracted keys.Expected behavior
The malformed member bad should be ignored, and later valid members should still be extracted.
Expected extracted baggage:
valid1=value1
valid2=value2
This matches the common behavior seen in OpenTelemetry Go, Java, Rust, and .NET, and is compatible with the W3C baggage specification's permissive invalid-input handling.
Actual behavior
Parsing stops at bad, so valid2=value2 is not extracted.
Actual extracted baggage:
valid1=value1
If the malformed member is first, for example:
baggage: bad,valid=valuethen no later valid baggage is extracted.
Regression?
No
Known Workarounds
Use a custom propagator or sanitize incoming baggage headers before passing them to DistributedContextPropagator, removing malformed list-members while keeping later valid members.
Configuration
Observed by reviewing the pinned dotnet/runtime implementation snapshot linked above.
Other information
It will be great to sync default behavior with other OTel implementations, especially .NET.
@cijothomas suggested to do this in open-telemetry/opentelemetry-dotnet#7374
Activity
dotnet-policy-service commentedon Jun 11, 2026
Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Jun 11, 2026
Tagging subscribers to this area: @steveisok, @dotnet/area-system-diagnostics-tracing
See info in area-owners.md if you want to be subscribed.
Fix W3CPropagator baggage parsing after malformed entries (#129287)
Fix W3CPropagator baggage parsing after malformed entries (#129287)
Fix W3CPropagator baggage parsing after malformed entries (dotnet#129287