[Breaking change]: Uri query redaction in HttpClient EventSource events #42794
Labels
breaking-change
Indicates a .NET Core breaking change
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
in-pr
This issue will be closed (fixed) by an active pull request.
Pri1
High priority, do before Pri2 and Pri3
📌 seQUESTered
Identifies that an issue has been imported into Quest.
Description
In .NET 9, the default behavior of
EventSource
events emitted byHttpClient
/SocketsHttpHandler
has been modified to scrub query strings (EventSource
name:System.Net.Http
). This change is aimed at enhancing privacy by preventing the logging of potentially sensitive information contained in query strings. For scenarios where consuming query strings is necessary and deemed safe, this behavior can be overridden by enabling theSystem.Net.Http.DisableUriRedaction
AppContext switch or by setting theDOTNET_SYSTEM_NET_HTTP_DISABLEURIREDACTION
environment variable.Version
.NET 9 Preview 7
Previous behavior
Previously, events emitted by
HttpClient
/SocketsHttpHandler
included query string information, which could inadvertently expose sensitive information.New behavior
With the change in dotnet/runtime#104741, query strings are replaced by a
*
character inHttpClient
/SocketsHttpHandler
events by default. This affects specific events and parameters such aspathAndQuery
inRequestStart
andredirectUri
inRedirect
. Developers can enable query string logging globally by setting theSystem.Net.Http.DisableUriRedaction
AppContext switch or theDOTNET_SYSTEM_NET_HTTP_DISABLEURIREDACTION
environment variable.Type of breaking change
Reason for change
The primary reason for this change is to enhance privacy by reducing the risk of sensitive information being logged inadvertently. Query strings often contain sensitive data and redacting them from logs by default helps protect this information.
Recommended action
If you need query string information when consuming
HttpClient
/SocketsHttpHandler
events and you are confident that it is safe to do so, you can enable query string logging globally by setting theSystem.Net.Http.DisableUriRedaction
AppContext switch or theDOTNET_SYSTEM_NET_HTTP_DISABLEURIREDACTION
environment variable. Otherwise, no action is required, and the default behavior will help enhance the privacy aspects of your application.If you are using
IHttpClientFactory
, note that these switches will also disable query string redaction in the defaultIHttpClientFactory
logs.Feature area
Networking
Affected APIs
System.Net.Http.SocketsHttpHandler.Send(...)
(overridesHttpMessageHandler.Send(...)
)System.Net.Http.SocketsHttpHandler.SendAsync(...)
(overridesHttpMessageHandler.SendAsync(...)
)Associated WorkItem - 340217
The text was updated successfully, but these errors were encountered: