Skip to content

Harden identity redirect handling in Blazor template - #70796

Merged
oroztocil merged 5 commits into
mainfrom
oroztocil/identity-redirect-hardening
Nov 25, 2026
Merged

oroztocil merged 5 commits into
mainfrom
oroztocil/identity-redirect-hardening

Conversation

@oroztocil

@oroztocil oroztocil commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

IdentityRedirectManager.RedirectTo in the Blazor Web App template validated the raw redirect string, and that check could be bypassed. ToBaseRelativePath strips the app's base URI and can leave a network-path reference such as //evil.example (or \/evil.example), which NavigateTo then resolves to another host.

This change resolves the URI against the app's base URI and only uses it if the result stays within the app. Anything else redirects to the home page instead of throwing. The app root without a trailing slash (for example /app?page=2) is still accepted, matching ToBaseRelativePath. The path is compared ordinally, so a path base with different casing such as /APP/ is rejected, while scheme and host stay case-insensitive because System.Uri normalizes them.

This is the reference for the recommended code. Once it's merged, the other places that ship this kind of code will be checked against it:

Validation: checked with a generated app in Chrome and against a set of valid, malicious and malformed return URLs with root and /app/ base paths. The existing template tests cover the valid redirects.

Fixes #70797

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Nov 23, 2026
@oroztocil
oroztocil marked this pull request as ready for review November 23, 2026 18:42
@oroztocil
oroztocil requested a review from a team as a code owner November 23, 2026 18:42
Copilot AI balanced review requested due to automatic review settings November 23, 2026 18:42

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

The redirect logic loses query strings and fragments for valid slashless app-root URLs, and the new URI-resolution and fallback behavior lacks regression coverage.

2 open issues
What changed in this PR

This PR updates identity redirects in the Blazor Web App template to validate resolved destinations against the application’s base URI.

Changes:

  • Resolve redirect input to an absolute URI before validation.
  • Fall back to the app’s home page when resolution fails or the destination is outside the base URI.
  • Pass the validated absolute URI directly to NavigateTo.
File Description
src/​ProjectTemplates/​Web.ProjectTemplates/​content/​BlazorWeb-CSharp/​BlazorWebCSharp.1/​Components/​Account/​IdentityRedirectManager.cs Replaces raw-input validation with resolved-URI validation and a home-page fallback.

Review effort: Balanced

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

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot 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.

Source-only review of frozen head d06e03409b7d07d6863ec9d53cb91219d45f67b1.

One unresolved P2 candidate is attached inline: the new OrdinalIgnoreCase containment check accepts a case-different application path, but the material hosting outcome is not established by the frozen repository contracts or available immutable evidence.

Existing-feedback coverage: No supported duplicate was republished. The earlier query/fragment thread (#discussion_r4670392025) is contradicted by the current head's GetLeftPart(UriPartial.Path) + "/" handling while retaining absoluteUri; the test-only thread (#discussion_r4670392066) does not establish a concrete behavioral defect.

Unresolved: Case-sensitive deployment behavior for /app/ versus /APP/; missing target-version System.Uri contract/validation, exact query-binding evidence, and a binding hosting contract or immutable artifact establishing the consumer-visible result.

DISCARDED
  • External origins and sibling paths such as /app2 are rejected by the new boundary check.
  • Query strings and fragments remain in absoluteUri.AbsoluteUri; the slashless app-root case is accepted by the appended / comparison.
  • Null, empty, malformed, and ordinary relative inputs resolve or fall back as shown by frozen source.
  • No applicable API, lifecycle, resource, concurrency, build, packaging, trimming, analyzer, or other source-backed regression was found.

Per-guide completion: docs/CrossCuttingGuidance.md complete; assessed scope, compatibility, URI correctness, nullability, exceptions, path/casing behavior, templates, consumers, and test-source coverage. Execution, tests, CI, browser workflows, implementation samples, and security implications were excluded by the supplied source-only policy.

Uncovered: No materially changed area lacked a routed guide.

Provenance: Bundle v2; guidance commit 635a8e68e7ebb2408701dae39aba97b383984299; merge base/base tip 635a8e68e7ebb2408701dae39aba97b383984299; independent guide worker and candidate verifier both used gpt-5.6-sol (reasoning effort not supplied; runtime default).

Test boundary and limitations: No target code or tests were executed. Proof is source-only and limited to tracked Git bytes; symlinks, submodules, LFS targets, runtime/BCL behavior, external hosting behavior, and feedback posted after bundle preparation were not observable.

Generated by ASP.NET Core Pull Request Review for #70796 · copilot · gpt56 · 91.4 AIC · ⌖ 8.63 AIC · ⊞ 20.3K
Comment /review to run again

oroztocil and others added 2 commits November 24, 2026 00:49
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@oroztocil

Copy link
Copy Markdown
Member Author

I rewrote the code comments with the perspective that this is guidance for users of the templates, not framework code.

@oroztocil
oroztocil merged commit c056567 into main Nov 25, 2026
29 checks passed
@oroztocil
oroztocil deleted the oroztocil/identity-redirect-hardening branch November 25, 2026 11:33
@github-actions

Copy link
Copy Markdown
Contributor

ℹ️ This pull request wasn't processed automatically.

This change requires specialized review. Please confirm whether documentation updates are needed and handle them through the appropriate process.

@oroztocil

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@oroztocil

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

@oroztocil oroztocil added area-blazor Includes: Blazor, Razor Components and removed area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI labels Nov 25, 2026
wtgodbe pushed a commit that referenced this pull request Nov 25, 2026
Co-authored-by: Ondřej Roztočil <roztocil@outlook.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 26, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 2b9c56ae Deployed Nov 25, 2026 by oroztocil via conclusion #459
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Open redirect possible in Blazor template IdentityRedirectManager.RedirectTo

4 participants