Skip to content

Harden open redirect check in Blazor Identity templates - #3978

Open
oroztocil wants to merge 2 commits into
dotnet:mainfrom
oroztocil:oroztocil/blazor-identity-redirect-hardening
Open

oroztocil wants to merge 2 commits into
dotnet:mainfrom
oroztocil:oroztocil/blazor-identity-redirect-hardening

Conversation

@oroztocil

@oroztocil oroztocil commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

The Blazor Identity scaffolder templates generate an IdentityRedirectManager.RedirectTo whose open redirect check can be bypassed. The net8.0, net9.0 and dotnet-aspnet-codegenerator templates only check Uri.IsWellFormedUriString(uri, UriKind.Relative), which accepts //evil.example. The net10.0 and net11.0 templates also reject a leading //, but https://<app>///evil.example goes through ToBaseRelativePath, which returns //evil.example without checking it again.

This changes all of these templates to resolve the URI against NavigationManager.BaseUri and only redirect to it if the result stays within the app. Anything else redirects to the home page. The code matches the recommended code merged in dotnet/aspnetcore#70796.

Changes:

  • dotnet-scaffold Blazor Identity templates for net8.0 to net11.0 (.tt and the preprocessed .cs)
  • dotnet-aspnet-codegenerator (VS.Web.CG.Mvc) Blazor Identity template (.tt and .cs)
  • net10.0 and net11.0 Blazor Identity test baselines

In the preprocessed .cs files, only the affected template text was updated, because some of them already differ from their .tt in unrelated ways. That drift is fixed separately in #3980.

Validation: dotnet-scaffold and VS.Web.CG.Mvc build, and the Blazor Identity baseline tests (net10.0, net11.0) and integration tests (net8.0, net9.0) pass.

release/10.0 has the same check in the VS.Web.CG.Mvc template, but publishing from that branch appears to be disabled. Let me know if 10.0.x dotnet-aspnet-codegenerator users need an update too.

Fixes #3977

- Resolve the URI passed to IdentityRedirectManager.RedirectTo against NavigationManager.BaseUri and only navigate to it if it stays within the app; otherwise fall back to the base URI.
- Apply the change to the net8.0, net9.0, net10.0 and net11.0 dotnet-scaffold templates and the VS.Web.CG.Mvc template, and update the net10.0 and net11.0 baselines.
- Aligns the templates with dotnet/aspnetcore#70796.

Fixes dotnet#3977

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@oroztocil
oroztocil marked this pull request as ready for review November 25, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blazor Identity scaffolders generate IdentityRedirectManager code that allows open redirects

1 participant