Skip to content

System.Net.Http.DiagnosticsHandler.SendAsync throws if Activity.Current.Baggage contains values that can't be parsed by NameValueHeaderValue after UrlEncoding #36908

@alexperovich

Description

@alexperovich

Description

This old issue #27106, was claimed to be fixed... but it is not fixed. In reality, the UrlEncoding used to "fix" the above issue breaks my workaround of quoting all the values.
This can be reproduced with:

var act = new Activity("test");
act.AddBaggage("test", "\"HelixAPI.Pages.Account.AccountController.SignIn (HelixAPI)\"");
act.Start();
try
{
	using (var c = new HttpClient())
	{
		await c.GetStringAsync("https://google.com");
	}
}
finally
{
	act.Stop();
}

This code throws the following exception

FormatException: The format of value '%22HelixAPI.Pages.Account.AccountController.SignIn+(HelixAPI)%22' is invalid.

Configuration

.NET Core 3.1, on windows 10
This isn't specific to any configuration

Regression?

This was a bug in older versions of .net core, it is still broken.

Other information

The bug is here: https://source.dot.net/#System.Net.Http/System/Net/Http/DiagnosticsHandler.cs,284

This should 100% not be using something that explodes when strange values are passed. This means that anywhere in the code of any program, if something completely benign is added to Activity.Current.Baggage, any HttpClient calls will fail.

If using NameValueHeaderValue is important for some reason.... at least it shouldn't crash the entire asp.net request because of a single baggage thingy.

Metadata

Metadata

Labels

area-System.Diagnosticsbughelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions