Conversation
Validate that returnUrl is a local path before redirecting. Reject absolute URLs, protocol-relative URLs (//), and backslash escape URLs (/\) to prevent open redirect attacks. Add unit tests covering malicious returnUrl values.
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15952Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15952" |
There was a problem hiding this comment.
Pull request overview
This PR addresses an open redirect vulnerability in ValidateTokenMiddleware by validating the returnUrl query parameter before redirecting, preventing redirects to external/malicious destinations after authentication.
Changes:
- Add a local-URL validation helper (
IsLocalUrl) and gate redirects on it. - Add unit tests covering several non-local
returnUrlpatterns (absolute, protocol-relative, and backslash-escape) for both Unsecured and BrowserToken auth modes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Aspire.Dashboard/Model/ValidateTokenMiddleware.cs | Validates returnUrl via a local-URL check before calling Response.Redirect, otherwise falls back to the default resources URL. |
| tests/Aspire.Dashboard.Tests/Middleware/ValidateTokenMiddlewareTests.cs | Adds coverage ensuring malicious/non-local returnUrl inputs do not influence the post-login redirect target. |
Incomplete fix —
|
… redirect - Extract IsLocalUrl into UrlValidationHelper.cs shared utility - Add IsSafeRedirectUrl that validates URI format and locality - Fix Login.razor.cs GetRedirectUrl() to validate ReturnUrl - Remove inlined IsLocalUrl from ValidateTokenMiddleware
|
🎬 CLI E2E Test Recordings — 56 recordings uploaded (commit View recordings
📹 Recordings uploaded automatically from CI run #24115336932 |
|
No documentation updates are required for this PR. This is an internal security bug fix that:
No changes to the aspire.dev documentation site are needed.
|
Description
Fix an open redirect vulnerability in
ValidateTokenMiddleware. ThereturnUrlquery parameter was used directly inResponse.Redirectwithout validation, allowing an attacker to craft a login URL that redirects users to an external malicious site after authentication.The fix adds an
IsLocalUrlcheck (matching ASP.NET Core'sIUrlHelper.IsLocalUrllogic) that only allows redirect URLs starting with/while rejecting protocol-relative (//) and backslash escape (/\) patterns. If validation fails, the middleware falls back to the default resources URL.Unit tests are added covering absolute URLs (
https://evil.com,http://evil.com), protocol-relative URLs (//evil.com), and backslash escape URLs (/\evil.com) for both Unsecured and BrowserToken auth modes.Checklist