Skip to content

Validate return URLs in Blazor samples - #693

Merged
oroztocil merged 3 commits into
mainfrom
oroztocil-return-url-validation
Nov 25, 2026
Merged

oroztocil merged 3 commits into
mainfrom
oroztocil-return-url-validation

Conversation

@oroztocil

@oroztocil oroztocil commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Several samples use a return URL from the query string or a form without checking that it points back to the app. A crafted link can send users to another site. In the standalone WebAssembly Identity sample and the general Blazor samples, a javascript: return URL also runs script on the app's origin.

All of them now resolve the return URL against the app's base URI and only use it if the result stays within the app. The code matches the recommended code merged in dotnet/aspnetcore#70796.

Changes:

  • OIDC and Entra BFF samples (LoginLogoutEndpointRouteBuilderExtensions.cs, 8.0 to 10.0): /login and /logout reduced absolute return URLs to their PathAndQuery, so https://host//evil.example became //evil.example. They now validate the return URL and fall back to the app root. The base URI is built from the request, including PathBase, which also resolves the existing TODO.
  • BlazorWebAssemblyStandaloneWithIdentity (Login.razor, 8.0 to 10.0): ReturnUrl was passed directly to NavigationManager.NavigateTo. It now only navigates to URLs within the app.
  • MauiBlazorWebIdentity (IdentityRedirectManager.cs, 9.0 and 10.0): the URI was only checked for being well formed. It now uses the template's check.
  • General Blazor samples (PetDetail.razor, 7.0 to 10.0): ReturnUrl was rendered directly as the "Return" link. The link now points to ReturnUrl only if it's within the app, and to the app root otherwise.

Validation: all changed projects build. The standalone WebAssembly Identity sample (8.0 to 10.0) and the 10.0 PetDetail page (Web App and WebAssembly) were tested in Chrome. javascript: and external return URLs no longer run or redirect, and in-app return URLs still work. The OIDC and Entra samples weren't run end to end because they need a real identity provider.

Fixes #692

Resolve return URLs against the app's base URI and only redirect to them if they stay within the app. This aligns the OIDC, Entra, standalone WebAssembly Identity and MAUI Blazor Web Identity samples with dotnet/aspnetcore#70796.

Fixes #692
Only link back to ReturnUrl when it resolves to a URI within the app, so the Return link can't point to another site or run a javascript: URL.

Contributes to #692
@oroztocil oroztocil changed the title Validate return URLs in authentication samples Validate return URLs in Blazor samples Nov 24, 2026
@oroztocil
oroztocil marked this pull request as ready for review November 25, 2026 11:51
@oroztocil
oroztocil requested review from guardrex and a balanced review from Copilot November 25, 2026 12:26

Copilot AI left a comment

Copy link
Copy Markdown

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 authentication and navigation return-URL validation changes.

No open issues 🎉

What changed in this PR

This PR addresses #692 by validating return URLs across Blazor authentication and navigation samples, preventing external redirects and script URLs while preserving navigation within the app.

Changes:

  • Validate OIDC and Entra login/logout destinations against the request’s app base URI, including PathBase, with an app-root fallback.
  • Restrict standalone WebAssembly login navigation and MAUI web Identity redirects to destinations within the app.
  • Validate PetDetail return links and fall back to the app root for invalid destinations.
File Description
9.0/​MauiBlazorWebIdentity/​MauiBlazorWeb/​MauiBlazorWeb.Web/​Components/​Account/​IdentityRedirectManager.cs Validate Identity redirects with an app-root fallback.
9.0/​BlazorWebAssemblyStandaloneWithIdentity/​BlazorWasmAuth/​Components/​Identity/​Login.razor Restrict post-login navigation to the app.
9.0/​BlazorWebAppOidcBffServer/​BlazorWebAppOidcServer/​LoginLogoutEndpointRouteBuilderExtensions.cs Validate authentication return URLs using PathBase.
9.0/​BlazorWebAppOidcBffAutoYarpAspire/​BlazorWebAppOidc/​LoginLogoutEndpointRouteBuilderExtensions.cs Validate authentication return URLs using PathBase.
9.0/​BlazorWebAppOidcBffAuto/​BlazorWebAppOidc/​LoginLogoutEndpointRouteBuilderExtensions.cs Validate authentication return URLs using PathBase.
9.0/​BlazorWebAppEntraBffYarpAspire/​BlazorWebAppEntra/​LoginLogoutEndpointRouteBuilderExtensions.cs Validate Entra return URLs using PathBase.
9.0/​BlazorWebAppEntraBff/​BlazorWebAppEntra/​LoginLogoutEndpointRouteBuilderExtensions.cs Replace path extraction with app-boundary validation.
9.0/​BlazorSample_WebAssembly/​Pages/​PetDetail.razor Validate return links with an app-root fallback.
9.0/​BlazorSample_BlazorWebApp/​Components/​Pages/​PetDetail.razor Validate return links with an app-root fallback.
8.0/​BlazorWebAssemblyStandaloneWithIdentity/​BlazorWasmAuth/​Components/​Identity/​Login.razor Restrict post-login navigation to the app.
8.0/​BlazorWebAppOidcServer/​BlazorWebAppOidcServer/​LoginLogoutEndpointRouteBuilderExtensions.cs Validate authentication return URLs using PathBase.
8.0/​BlazorWebAppOidcBff/​BlazorWebAppOidc/​LoginLogoutEndpointRouteBuilderExtensions.cs Validate authentication return URLs using PathBase.
8.0/​BlazorWebAppOidc/​BlazorWebAppOidc/​LoginLogoutEndpointRouteBuilderExtensions.cs Validate authentication return URLs using PathBase.
8.0/​BlazorSample_WebAssembly/​Pages/​PetDetail.razor Validate return links with an app-root fallback.
8.0/​BlazorSample_BlazorWebApp/​Components/​Pages/​PetDetail.razor Validate return links with an app-root fallback.
7.0/​BlazorSample_WebAssembly/​Pages/​templated-components/​PetDetail.razor Validate return links with an app-root fallback.
7.0/​BlazorSample_Server/​Pages/​templated-components/​PetDetail.razor Validate return links with an app-root fallback.
10.0/​MauiBlazorWebIdentity/​MauiBlazorWeb.Web/​Components/​Account/​IdentityRedirectManager.cs Validate Identity redirects with an app-root fallback.
10.0/​BlazorWebAssemblyStandaloneWithIdentity/​BlazorWasmAuth/​Pages/​Identity/​Login.razor Restrict post-login navigation to the app.
10.0/​BlazorWebAppOidcBffServer/​BlazorWebAppOidcServer/​LoginLogoutEndpointRouteBuilderExtensions.cs Validate authentication return URLs using PathBase.
10.0/​BlazorWebAppOidcBffAutoYarpAspire/​BlazorWebAppOidc/​LoginLogoutEndpointRouteBuilderExtensions.cs Validate authentication return URLs using PathBase.
10.0/​BlazorWebAppOidcBffAuto/​BlazorWebAppOidc/​LoginLogoutEndpointRouteBuilderExtensions.cs Validate authentication return URLs using PathBase.
10.0/​BlazorWebAppEntraBffYarpAspire/​BlazorWebAppEntra/​LoginLogoutEndpointRouteBuilderExtensions.cs Validate Entra return URLs using PathBase.
10.0/​BlazorWebAppEntraBff/​BlazorWebAppEntra/​LoginLogoutEndpointRouteBuilderExtensions.cs Replace path extraction with app-boundary validation.
10.0/​BlazorSample_BlazorWebAssembly/​Pages/​PetDetail.razor Validate return links with an app-root fallback.
10.0/​BlazorSample_BlazorWebApp/​Components/​Pages/​PetDetail.razor Validate return links with an app-root fallback.

Review effort: Balanced

@oroztocil
oroztocil merged commit 5840dd8 into main Nov 25, 2026
3 of 4 checks passed
@oroztocil
oroztocil deleted the oroztocil-return-url-validation branch November 25, 2026 14:12
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 samples use return URLs without validating them

3 participants