Visitar URL original
Fix route parameter redaction when the value contains the following literal by evgenyfedorov2 · Pull Request #7828 · dotnet/extensions · GitHub
Skip to content

Fix route parameter redaction when the value contains the following literal - #7828

Merged
evgenyfedorov2 merged 6 commits into
mainfrom
evgenyfedorov2-fix-route-redaction-complex-segments
Oct 13, 2026
Merged

evgenyfedorov2 merged 6 commits into
mainfrom
evgenyfedorov2-fix-route-redaction-complex-segments

Conversation

@evgenyfedorov2

@evgenyfedorov2 evgenyfedorov2 commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #7826

For a route parameter followed by a literal in the same path segment, e.g. {token}.{format}:

  • HttpRouteFormatter split the value at the first occurrence of the next literal's first char: /a/{token}.{format} + /a/part1.part2.part3.json → a/[REDACTED].part2.part3.json.
  • HttpRouteParser took the whole path segment: /b/{format}.{token} + /b/json.secret → format=json.secret, token="".

Fix: match the literals that follow the parameter within the same path segment from right to left, ignoring case, as ASP.NET Core routing does (one small helper used by both). If they can't be matched, the previous logic is used unchanged.

Added tests for the cases above; they fail without the fix.

Microsoft Reviewers: Open in CodeFlow

…iteral

HttpRouteFormatter split a parameter value at the first occurrence of the next
literal's first char, and HttpRouteParser took the whole path segment, so values
of routes like {token}.{format} were split incorrectly and parts of a sensitive
value could be logged unredacted. Match the literals that follow a parameter in
the same path segment from right to left, as ASP.NET Core routing does.

Fixes #7826

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@evgenyfedorov2
evgenyfedorov2 force-pushed the evgenyfedorov2-fix-route-redaction-complex-segments branch from 8b5a72e to 77a8c1c Compare October 12, 2026 12:11
@evgenyfedorov2 evgenyfedorov2 changed the title Fix route parameter redaction leak in complex route segments Fix route parameter redaction when the value contains the following literal Oct 12, 2026
Evgenii Fedorov and others added 4 commits October 12, 2026 14:20
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@evgenyfedorov2
evgenyfedorov2 marked this pull request as ready for review October 12, 2026 12:44
@evgenyfedorov2
evgenyfedorov2 requested a review from a team as a code owner October 12, 2026 12:44
Copilot AI balanced review requested due to automatic review settings October 12, 2026 12:44

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.

🟡 Changes recommended

Case-sensitive literal matching can still expose classified values when route and path casing differ.

1 open finding
What changed in this PR

Fixes route-parameter extraction and redaction for complex path segments by matching trailing literals right-to-left.

Changes:

  • Adds shared complex-segment matching logic.
  • Updates parser and formatter behavior.
  • Adds regression tests.
File Description
HttpRouteParser.cs Implements shared literal matching.
HttpRouteFormatter.cs Uses improved parameter boundaries.
HttpParserTests.cs Tests extraction scenarios.
HttpRouteFormatterTests.cs Tests complete redaction.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@dotnet-comment-bot

Copy link
Copy Markdown
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.Diagnostics.Testing Line 99 98.65 🔻
Microsoft.Extensions.Telemetry Line 93 92.41 🔻
Microsoft.Extensions.AI.OpenAI Line 75 68.34 🔻
Microsoft.Extensions.AI.OpenAI Branch 75 57.74 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Line 75 4.46 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Branch 75 0 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Line 99 96.03 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Branch 99 92.76 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Line 99 97.73 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Line 75 71.61 🔻
Microsoft.Extensions.ServiceDiscovery Line 75 67.96 🔻
Microsoft.Extensions.ServiceDiscovery Branch 75 71.43 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Line 75 42.11 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Branch 75 42.86 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Line 75 73.85 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Branch 75 70 🔻
Microsoft.Extensions.VectorData.Abstractions Line 75 37.39 🔻
Microsoft.Extensions.VectorData.Abstractions Branch 75 22.73 🔻

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

Project Expected Actual
Microsoft.Extensions.Http.Diagnostics 94 95
Microsoft.Gen.BuildMetadata 97 100
Microsoft.Gen.MetadataExtractor 57 73
Microsoft.Gen.MetricsReports 67 69
Microsoft.Extensions.AI.Abstractions 82 86
Microsoft.Extensions.AI.Evaluation.NLP 0 78
Microsoft.Extensions.Caching.Hybrid 82 85
Microsoft.Extensions.DataIngestion 75 89
Microsoft.Extensions.DataIngestion.Markdig 75 90
Microsoft.Extensions.Http.Resilience 97 100

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

ASP.NET Core routing ignores case when matching literals, so a request such as
/a/part1.part2.json.ZIP matches route /a/{token}.{format}.zip. The ordinal match
returned -1 for it and both callers fell back to their old splitting, which
leaked part of the token.

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

Copy link
Copy Markdown
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.Diagnostics.Testing Line 99 98.65 🔻
Microsoft.Extensions.Telemetry Line 93 92.41 🔻
Microsoft.Extensions.AI.OpenAI Line 75 68.34 🔻
Microsoft.Extensions.AI.OpenAI Branch 75 57.74 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Line 75 4.46 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Branch 75 0 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Line 99 96.03 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Branch 99 92.76 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Line 99 97.73 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Line 75 68.32 🔻
Microsoft.Extensions.ServiceDiscovery Line 75 68.42 🔻
Microsoft.Extensions.ServiceDiscovery Branch 75 71.43 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Line 75 42.11 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Branch 75 42.86 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Line 75 73.85 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Branch 75 70 🔻
Microsoft.Extensions.VectorData.Abstractions Line 75 37.39 🔻
Microsoft.Extensions.VectorData.Abstractions Branch 75 22.73 🔻

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

Project Expected Actual
Microsoft.Extensions.Http.Diagnostics 94 95
Microsoft.Gen.BuildMetadata 97 100
Microsoft.Gen.MetadataExtractor 57 73
Microsoft.Gen.MetricsReports 67 69
Microsoft.Extensions.AI.Abstractions 82 86
Microsoft.Extensions.AI.Evaluation.NLP 0 78
Microsoft.Extensions.Caching.Hybrid 82 89
Microsoft.Extensions.DataIngestion 75 89
Microsoft.Extensions.DataIngestion.Markdig 75 90
Microsoft.Extensions.Http.Resilience 97 100

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

@evgenyfedorov2
evgenyfedorov2 merged commit e234d0d into main Oct 13, 2026
5 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpRouteFormatter - Log redaction leaks replayable bearer token

4 participants