Skip to content

Fix route parameter redaction for actions sharing a route template - #7933

Merged
evgenyfedorov2 merged 5 commits into
dotnet:mainfrom
evgenyfedorov2:evgenyfedorov2-fix-route-redaction-cache
Nov 12, 2026
Merged

evgenyfedorov2 merged 5 commits into
dotnet:mainfrom
evgenyfedorov2:evgenyfedorov2-fix-route-redaction-cache

Conversation

@evgenyfedorov2

@evgenyfedorov2 evgenyfedorov2 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

IncomingHttpRouteUtility cached route parameter classifications by route template, but several controller actions can have the same template: one template on different HTTP methods, or all actions of a conventional route. The classifications of the first action requested were then used for all of them. For example, with these two actions:

[HttpGet("api/users/{userId}")]
public IActionResult Get([NoDataClassification] string userId) => Ok();

[HttpPost("api/users/{userId}")]
public IActionResult Update([PrivateData] string userId) => Ok();

after one GET request, the user ID of every POST request is not redacted: POST /api/users/123 is logged as api/users/123.

Fix: cache the classifications per endpoint, and only for controller endpoints, since other endpoints have no parameter classifications.

Microsoft Reviewers: Open in CodeFlow

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change intended to prevent classification reuse across controller actions sharing a route template.

No open issues 🎉

What changed in this PR

Fixes incoming HTTP log redaction when controller actions share a route template, preventing one action’s parameter classifications from being reused for another.

Changes:

  • Caches parameter classifications by endpoint rather than route template, and skips caching endpoints without controller metadata.
  • Adds unit and acceptance tests for shared templates across HTTP methods and conventional routes.
  • Replaces NETCOREAPP3_1_OR_GREATER guards with NET in the utility and its unit tests.
File Description
test/​Libraries/​Microsoft.AspNetCore.Diagnostics.Middleware.Tests/​Logging/​IncomingHttpRouteUtilityTests.cs Tests classification isolation between endpoints sharing a template; updates compilation guards.
test/​Libraries/​Microsoft.AspNetCore.Diagnostics.Middleware.Tests/​Logging/​ApiRoutingController.cs Adds GET and POST actions with different classifications on the same template.
test/​Libraries/​Microsoft.AspNetCore.Diagnostics.Middleware.Tests/​Logging/​AcceptanceTests.Routing.cs Tests redaction for actions sharing a conventional route.
test/​Libraries/​Microsoft.AspNetCore.Diagnostics.Middleware.Tests/​Logging/​AcceptanceTests.Mvc.cs Tests redaction for GET and POST actions sharing a template.
src/​Libraries/​Microsoft.AspNetCore.Diagnostics.Middleware/​Logging/​IncomingHttpRouteUtility.cs Keys the cache by endpoint, bypasses non-controller endpoints, and updates compilation guards.

Review effort: Balanced

@evgenyfedorov2
evgenyfedorov2 force-pushed the evgenyfedorov2-fix-route-redaction-cache branch 4 times, most recently from 85b3a98 to 19a479d Compare November 10, 2026 14:41
IncomingHttpRouteUtility cached route parameter classifications by route
template, but several controller actions can have the same template: one
template on different HTTP methods, or all actions of a conventional route.
The classifications of the first action requested were then used for all of
them. For example, with these two actions:

    [HttpGet("api/users/{userId}")]
    public IActionResult Get([NoDataClassification] string userId) => Ok();

    [HttpPost("api/users/{userId}")]
    public IActionResult Update([PrivateData] string userId) => Ok();

after one GET request, the user ID of every POST request was not redacted:
POST /api/users/123 was logged as api/users/123.

Cache the classifications per endpoint, and only for controller endpoints,
since other endpoints have no parameter classifications.

Also remove #if NETCOREAPP3_1_OR_GREATER and its dead #else code from the
changed files, since the library and its tests target only .NET.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@evgenyfedorov2
evgenyfedorov2 force-pushed the evgenyfedorov2-fix-route-redaction-cache branch from 19a479d to 53a7f83 Compare November 10, 2026 14:51
@evgenyfedorov2
evgenyfedorov2 marked this pull request as ready for review November 10, 2026 14:52
@evgenyfedorov2
evgenyfedorov2 requested a review from a team as a code owner November 10, 2026 14:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the endpoint-specific route-redaction change.

No open issues 🎉

Review effort: Balanced

@dotnet-comment-bot

Copy link
Copy Markdown
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.AI Line 89 87.81 🔻
Microsoft.Extensions.AI Branch 89 79.23 🔻
Microsoft.Extensions.AI.OpenAI Line 75 68.8 🔻
Microsoft.Extensions.AI.OpenAI Branch 75 60.3 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Line 75 4.46 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Branch 75 0.75 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Line 99 96.06 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Branch 99 92.28 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Line 99 97.73 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Branch 99 92.86 🔻
Microsoft.Extensions.Diagnostics.Testing Line 99 98.22 🔻
Microsoft.Extensions.Diagnostics.Testing Branch 99 93.66 🔻
Microsoft.Extensions.ServiceDiscovery Line 75 58.1 🔻
Microsoft.Extensions.ServiceDiscovery Branch 75 64.41 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Line 75 41.14 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Branch 75 45.1 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Line 75 62.53 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Branch 75 73.96 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Line 75 73.85 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Branch 75 60 🔻
Microsoft.Extensions.Telemetry Line 93 90.47 🔻
Microsoft.Extensions.Telemetry Branch 93 86.83 🔻
Microsoft.Extensions.VectorData.Abstractions Line 75 32.15 🔻
Microsoft.Extensions.VectorData.Abstractions Branch 75 26.31 🔻

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.AI.Evaluation.NLP 0 74
Microsoft.Extensions.Caching.Hybrid 81 83
Microsoft.Extensions.DataIngestion 75 77
Microsoft.Extensions.DataIngestion.Markdig 75 88
Microsoft.Extensions.DocumentExtraction 80 94
Microsoft.Extensions.DocumentExtraction.Abstractions 80 100
Microsoft.Extensions.Documents.Abstractions 80 98
Microsoft.Gen.MetadataExtractor 57 72
Microsoft.Gen.MetricsReports 67 69

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1673031&view=codecoverage-tab

evgenyfedorov2 and others added 2 commits November 12, 2026 08:56
The cache of route parameter classifications held its endpoints for the
lifetime of the app. MVC builds new endpoints for all actions whenever its
list of actions changes, for example on hot reload or when an app's
IActionDescriptorChangeProvider signals a change, so the old endpoints
piled up in the cache.

Use a ConditionalWeakTable keyed by endpoint, so each entry goes away
together with its endpoint.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
GetSensitiveParameter_ActionsWithSameRoute_ReturnsSensitiveParametersOfEachAction
already checks that endpoints sharing a route template get their own
classifications, and the logging interceptor that the acceptance tests go
through is unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the endpoint-specific route parameter redaction fix.

No open issues 🎉

Review effort: Balanced

@evgenyfedorov2
evgenyfedorov2 enabled auto-merge (squash) November 12, 2026 12:36
@dotnet-comment-bot

Copy link
Copy Markdown
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.AI Line 89 87.81 🔻
Microsoft.Extensions.AI Branch 89 79.23 🔻
Microsoft.Extensions.AI.OpenAI Line 75 68.8 🔻
Microsoft.Extensions.AI.OpenAI Branch 75 60.3 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Line 75 4.46 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Branch 75 0.75 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Line 99 96.06 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Branch 99 92.28 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Line 99 97.73 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Branch 99 92.86 🔻
Microsoft.Extensions.Diagnostics.Testing Line 99 98.22 🔻
Microsoft.Extensions.Diagnostics.Testing Branch 99 93.66 🔻
Microsoft.Extensions.ServiceDiscovery Line 75 59.38 🔻
Microsoft.Extensions.ServiceDiscovery Branch 75 64.41 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Line 75 41.14 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Branch 75 45.1 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Line 75 60.22 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Branch 75 74.08 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Line 75 73.85 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Branch 75 60 🔻
Microsoft.Extensions.Telemetry Line 93 90.47 🔻
Microsoft.Extensions.Telemetry Branch 93 86.83 🔻
Microsoft.Extensions.VectorData.Abstractions Line 75 32.15 🔻
Microsoft.Extensions.VectorData.Abstractions Branch 75 26.31 🔻

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.AI.Evaluation.NLP 0 74
Microsoft.Extensions.Caching.Hybrid 81 83
Microsoft.Extensions.DataIngestion 75 77
Microsoft.Extensions.DataIngestion.Markdig 75 88
Microsoft.Extensions.DocumentExtraction 80 94
Microsoft.Extensions.DocumentExtraction.Abstractions 80 100
Microsoft.Extensions.Documents.Abstractions 80 98
Microsoft.Gen.MetadataExtractor 57 72
Microsoft.Gen.MetricsReports 67 69

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1677357&view=codecoverage-tab

@evgenyfedorov2
evgenyfedorov2 merged commit e29d20a into dotnet:main Nov 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants