Skip to content

fix(auth): preserve returnUrl in local fallback login#399

Merged
mpaulosky merged 1 commit into
devfrom
squad/398-preserve-returnurl-login-fallback
May 25, 2026
Merged

fix(auth): preserve returnUrl in local fallback login#399
mpaulosky merged 1 commit into
devfrom
squad/398-preserve-returnurl-login-fallback

Conversation

@mpaulosky

Copy link
Copy Markdown
Owner

Summary

  • preserve the validated returnUrl when placeholder Auth0 config redirects /Account/Login to /test/login
  • teach the local test-login endpoint to honor the same safe relative return path
  • strengthen AppHost and architecture coverage for the fallback redirect contract

Context

Closes #398
Working as Gandalf (Security / Auth)

Copilot AI review requested due to automatic review settings May 25, 2026 16:14
@github-actions

Copy link
Copy Markdown
Contributor

🏗️ PR Added to Squad Triage Queue

This PR has been labeled with squad and added to the triage queue.

Next steps:

  • The squad Lead will review and assign to an appropriate team member
  • A squad:member label will be added after triage

If you know which squad member should handle this, you can add the appropriate squad:member label yourself.

@github-actions github-actions Bot added the squad Squad triage inbox — Lead will assign to a member label May 25, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Pull request overview

This PR refines the Development/Testing Auth0-placeholder fallback so /Account/Login preserves a validated returnUrl when redirecting to the local /test/login endpoint, and updates /test/login to redirect back to the same safe return path after setting the test auth cookie. It also adds AppHost and architecture-level coverage to lock in the redirect contract and improves AppHost test determinism by clearing Auth0 environment variables inside the spawned web resource.

Changes:

  • Preserve (and forward) returnUrl when /Account/Login short-circuits to /test/login under placeholder Auth0 config.
  • Teach /test/login to redirect to the same validated safe relative return path (instead of always /).
  • Add AppHost + architecture contract tests; clear Auth0 env vars in AppHost fixtures for deterministic placeholder behavior; add docs troubleshooting note.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/Architecture.Tests/AuthFallbackContractTests.cs Adds a source-order contract test ensuring placeholder short-circuit occurs before OIDC challenge.
tests/AppHost.Tests/Tests/Auth/LoginFallbackTests.cs Adds runtime redirect assertions for /Account/Login and /test/login honoring returnUrl.
tests/AppHost.Tests/Infrastructure/ClearCommandAppFixture.cs Clears Auth0 env vars in the spawned web resource to force placeholder behavior in Testing.
tests/AppHost.Tests/Infrastructure/AspireManager.cs Clears Auth0 env vars (with logging) to keep AppHost tests deterministic even with ambient secrets.
src/Web/Program.cs Preserves returnUrl through placeholder fallback and redirects /test/login back to the requested path.
docs/AUTH0_SETUP.md Documents the IDX20803/test.auth0.com timeout pattern and the expected local fallback behavior.
.squad/agents/gimli/history.md Records testing/coverage work and validation notes for the auth fallback coverage changes.
.squad/agents/gandalf/history.md Reformats and records prior auth security findings and the placeholder-login approach.

Comment thread src/Web/Program.cs
Comment on lines 178 to 183
app.MapGet("/Account/Login", async (HttpContext ctx, string? returnUrl) =>
{
var safeReturn = !string.IsNullOrEmpty(returnUrl)
&& Uri.IsWellFormedUriString(returnUrl, UriKind.Relative)
? returnUrl
: "/";
Comment thread src/Web/Program.cs
Comment on lines 224 to 229
var roleValue = string.IsNullOrWhiteSpace(role) ? "user" : role;
var safeReturn = !string.IsNullOrEmpty(returnUrl)
&& Uri.IsWellFormedUriString(returnUrl, UriKind.Relative)
? returnUrl
: "/";

Comment on lines +22 to +26
var localRedirectIndex = loginHandlerSource.IndexOf(
"ctx.Response.Redirect($\"/test/login?returnUrl={Uri.EscapeDataString(safeReturn)}\")",
StringComparison.Ordinal);
var challengeIndex = loginHandlerSource.IndexOf(
"await ctx.ChallengeAsync(Auth0Constants.AuthenticationScheme, props).ConfigureAwait(false);",
Comment thread src/Web/Program.cs
Comment on lines 178 to 183
app.MapGet("/Account/Login", async (HttpContext ctx, string? returnUrl) =>
{
var safeReturn = !string.IsNullOrEmpty(returnUrl)
&& Uri.IsWellFormedUriString(returnUrl, UriKind.Relative)
? returnUrl
: "/";
@mpaulosky
mpaulosky force-pushed the squad/398-preserve-returnurl-login-fallback branch from 4da387d to 351153a Compare May 25, 2026 16:19
@github-actions

Copy link
Copy Markdown
Contributor

Test Results Summary

515 tests  +1   514 ✅ +1   32s ⏱️ ±0s
  6 suites ±0     1 💤 ±0 
  6 files   ±0     0 ❌ ±0 

Results for commit 351153a. ± Comparison against base commit 3dac6f1.

This pull request removes 1 and adds 2 tests. Note that renamed tests count towards both.
AppHost.Tests.LoginFallbackTests ‑ AccountLogin InTestingWithPlaceholderAuth0Config RedirectsToLocalTestLogin
AppHost.Tests.LoginFallbackTests ‑ AccountLogin InTestingWithPlaceholderAuth0Config RedirectsToLocalTestLoginWithReturnUrl
AppHost.Tests.LoginFallbackTests ‑ TestLogin InTestingWithReturnUrl RedirectsBackToRequestedPage

@codecov

codecov Bot commented May 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.46%. Comparing base (3dac6f1) to head (351153a).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #399   +/-   ##
=======================================
  Coverage   85.46%   85.46%           
=======================================
  Files          70       70           
  Lines        1693     1693           
  Branches      207      207           
=======================================
  Hits         1447     1447           
  Misses        166      166           
  Partials       80       80           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mpaulosky
mpaulosky merged commit 305bbf0 into dev May 25, 2026
18 checks passed
@mpaulosky
mpaulosky deleted the squad/398-preserve-returnurl-login-fallback branch May 25, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

squad Squad triage inbox — Lead will assign to a member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Sprint 20] Preserve returnUrl for local placeholder Auth0 login fallback

2 participants