feat(hosting): add url.query redaction for telemetry sensitive parameter#65369
Open
claudiogodoy99 wants to merge 4 commits intodotnet:mainfrom
Open
feat(hosting): add url.query redaction for telemetry sensitive parameter#65369claudiogodoy99 wants to merge 4 commits intodotnet:mainfrom
claudiogodoy99 wants to merge 4 commits intodotnet:mainfrom
Conversation
…ters Introduce UrlQueryRedactionOptions to redact sensitive query string values (e.g., tokens, passwords, API keys) from the url.query OpenTelemetry attribute on HTTP request activities. Configurable sensitive parameter names and placeholder text. Wired through GenericWebHostService, HostingApplication, and HostingApplicationDiagnostics. Includes unit tests.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in mechanism for emitting the OpenTelemetry url.query activity tag while redacting configured “sensitive” query-string parameters, to prevent secrets from being captured in HTTP server telemetry.
Changes:
- Introduces a new public
UrlQueryRedactionOptionsAPI to configure sensitive parameter names and a redaction placeholder. - Updates Hosting diagnostics/tag initialization to optionally add
url.querywith redaction applied. - Adds a helper (
HostingTelemetryHelpers.GetRedactedQueryString) and unit tests validating redaction behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Hosting/Hosting/test/HostingApplicationDiagnosticsTests.cs | Adds unit tests validating inclusion/exclusion and redaction behavior for url.query. |
| src/Hosting/Hosting/src/PublicAPI.Unshipped.txt | Declares the new public UrlQueryRedactionOptions API surface. |
| src/Hosting/Hosting/src/Internal/WebHost.cs | Attempts to resolve UrlQueryRedactionOptions from DI and pass to HostingApplication. |
| src/Hosting/Hosting/src/Internal/UrlQueryRedactionOptions.cs | Adds the new public options type and default sensitive parameter list. |
| src/Hosting/Hosting/src/Internal/HostingTelemetryHelpers.cs | Adds helper to redact sensitive query parameter values. |
| src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs | Optionally emits url.query tag during activity creation when options are provided. |
| src/Hosting/Hosting/src/Internal/HostingApplication.cs | Plumbs redaction options into diagnostics. |
| src/Hosting/Hosting/src/GenericHost/GenericWebHostService.cs | Attempts to resolve/pass redaction options in generic-host startup path. |
Contributor
Author
Performance ConcernsI've Benchmark some approaches for the new method Bench Results| Method | Categories | Mean | Error | StdDev | Gen0 | Allocated |
|------------------- |--------------- |------------:|-----------:|-----------:|-------:|----------:|
| ManyParams | 12_Params | 439.2046 ns | 20.5173 ns | 13.5709 ns | 0.1125 | 944 B |
| | | | | | | |
| AllSensitiveParams | 3_AllSensitive | 201.2194 ns | 9.4309 ns | 4.9325 ns | 0.0715 | 600 B |
| | | | | | | |
| NoSensitiveParams | 3_NonSensitive | 151.1875 ns | 5.1225 ns | 3.3882 ns | 0.0410 | 344 B |
| | | | | | | |
| MixedParams | 5_Mixed | 279.1219 ns | 14.9330 ns | 9.8773 ns | 0.0858 | 720 B |
| | | | | | | |
| EmptyQueryString | Empty | 0.9674 ns | 0.0814 ns | 0.0484 ns | - | - |
| | | | | | | |
| SingleParam | SingleParam | 81.2347 ns | 5.7101 ns | 3.7769 ns | 0.0257 | 216 B |
| | | | | | | |
| SpecialCharsParams | SpecialChars | 218.3186 ns | 6.4507 ns | 3.8387 ns | 0.0639 | 536 B |Bench Code |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This was referenced Feb 9, 2026
Open
Add explicit opt-in behavior for UrlQueryRedactionOptions to address PR feedback. IOptions<T> is always resolvable when AddOptions() is called, making nullable parameters ineffective for opt-in features. Changes: - Add IsEnabled property (defaults to false) to UrlQueryRedactionOptions - Check IsEnabled in HostingApplicationDiagnostics before redacting - Update PublicAPI.Unshipped.txt with new API surface - Fix formatting/indentation in HostingTelemetryHelpers.cs - Update tests to explicitly enable redaction when testing Users must now explicitly opt-in: services.Configure<UrlQueryRedactionOptions>(o => o.IsEnabled = true);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add configurable query string redaction for OpenTelemetry url.query attribute
Summary of the changes (Less than 80 chars)
Summary
This PR introduces configurable redaction of sensitive query string parameters in the
url.queryOpenTelemetry attribute for HTTP request activities, preventing sensitive data (tokens, passwords, API keys) from being exposed in telemetry.Changes
New
UrlQueryRedactionOptionsAPI:UrlQueryRedactionOptionsclass with configurable:SensitiveQueryParameters: HashSet of parameter names to redact (default includes:token,api_key,apikey,access_token,password,secret,auth)RedactedPlaceholder: Custom placeholder text (default:[Redacted])Core Integration:
GenericWebHostServiceto retrieve and passUrlQueryRedactionOptionsfrom DI containerHostingApplicationconstructor to accept optionalUrlQueryRedactionOptionsHostingApplicationDiagnosticsto apply redaction when settingurl.queryactivity tagHostingTelemetryHelpers.RedactQueryString()method to perform the actual redaction logic with URL encodingBehavior:
UrlQueryRedactionOptionsis NOT configured: The behavior remains exactly as before — theurl.queryattribute is not included in telemetry (fully backward compatible, no breaking changes)UrlQueryRedactionOptionsIS configured (via DI), theurl.queryattribute is included with sensitive values redactedTesting:
Motivation
Address issue: #64850