diff --git a/Server/src/SOR.Website/Pages/Auth/ForgotPassword.cshtml b/Server/src/SOR.Website/Pages/Auth/ForgotPassword.cshtml index c2aaf8f..26e792a 100644 --- a/Server/src/SOR.Website/Pages/Auth/ForgotPassword.cshtml +++ b/Server/src/SOR.Website/Pages/Auth/ForgotPassword.cshtml @@ -1,42 +1,3 @@ @page -@model ForgotPasswordModel -@{ - ViewData["Title"] = "Forgot Password"; -} - -
-
-

Reset Password

- - @if (Model.EmailSent) - { -
- If an account exists with that email, you'll receive a reset link shortly. - Check your spam folder if it doesn't arrive within a few minutes. -
- Back to Login - } - else - { -

Enter your account email and we'll send you a reset link.

- -
-
- - - -
- -
- - - } -
-
+@model SOR.Website.Pages.Auth.ForgotPasswordModel +@* This page is not rendered — the model redirects to /auth/challenge immediately. *@ diff --git a/Server/src/SOR.Website/Pages/Auth/ForgotPassword.cshtml.cs b/Server/src/SOR.Website/Pages/Auth/ForgotPassword.cshtml.cs index b0590ae..5f3865f 100644 --- a/Server/src/SOR.Website/Pages/Auth/ForgotPassword.cshtml.cs +++ b/Server/src/SOR.Website/Pages/Auth/ForgotPassword.cshtml.cs @@ -1,74 +1,15 @@ namespace SOR.Website.Pages.Auth; -using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.AspNetCore.RateLimiting; -using SOR.Database.Entities.Identity; /// -/// Initiates password reset by sending a reset link to the supplied email. -/// -/// Security controls: -/// - [EnableRateLimiting]: 3 attempts per IP per 15 minutes — limits reset spam. -/// - Anti-enumeration: ALWAYS shows the same success message regardless of whether -/// the email is registered. An attacker cannot probe which emails have accounts. -/// - Reset token generated by ASP.NET Core Identity's built-in TOTP token provider -/// (time-limited, single-use). The raw token is sent in the email link only. -/// - TODO: wire up an actual email provider. Until then the reset link is logged -/// (only in Development) so developers can test the flow. +/// Local account management is no longer handled by this site — Keycloak owns all +/// registration, password reset, and email verification flows. +/// Redirects to the Keycloak-hosted login/registration page. /// -[EnableRateLimiting("auth-reset")] -public sealed class ForgotPasswordModel( - UserManager userManager, - ILogger logger) : PageModel +public sealed class ForgotPasswordModel : PageModel { - [BindProperty] - public InputModel Input { get; set; } = new(); - - public bool EmailSent { get; private set; } - - public sealed class InputModel - { - [Required(ErrorMessage = "Email is required.")] - [EmailAddress(ErrorMessage = "Enter a valid email address.")] - [MaxLength(254)] - public string Email { get; set; } = string.Empty; - } - - public void OnGet() { } - - public async Task OnPostAsync() - { - if (!ModelState.IsValid) - return Page(); - - // Look up the user — but do not reveal whether the email is registered. - var user = await userManager.FindByEmailAsync(Input.Email); - - if (user is not null && !user.IsAi) - { - var token = await userManager.GeneratePasswordResetTokenAsync(user); - var resetLink = Url.Page( - "/Auth/ResetPassword", - pageHandler: null, - values: new { token, email = Input.Email }, - protocol: Request.Scheme); - - // TODO: send resetLink via email provider. - // Log in development only so the link is accessible for manual testing. - if (HttpContext.RequestServices - .GetRequiredService() - .IsDevelopment()) - { - logger.LogWarning("DEV ONLY — password reset link for {Email}: {Link}", - Input.Email, resetLink); - } - } - - // Always show the same message — anti-enumeration. - EmailSent = true; - return Page(); - } + public IActionResult OnGet() => Redirect("/auth/challenge"); + public IActionResult OnPost() => Redirect("/auth/challenge"); } diff --git a/Server/src/SOR.Website/Pages/Auth/Login.cshtml b/Server/src/SOR.Website/Pages/Auth/Login.cshtml index 2176fb7..bf8fe17 100644 --- a/Server/src/SOR.Website/Pages/Auth/Login.cshtml +++ b/Server/src/SOR.Website/Pages/Auth/Login.cshtml @@ -1,55 +1,3 @@ @page -@model LoginModel -@{ - ViewData["Title"] = "Log In"; -} - -
-
-

Log In

- - @if (Model.ErrorMessage is not null) - { - - } - - @* asp-page-handler is omitted — Razor Pages routes POST to OnPostAsync by default. - The form tag helper automatically injects the anti-forgery hidden field. *@ -
- - -
- - - -
- -
- - - -
- -
- - -
- - -
- - -
-
+@model SOR.Website.Pages.Auth.LoginModel +@* This page is not rendered — the model redirects to /auth/challenge immediately. *@ diff --git a/Server/src/SOR.Website/Pages/Auth/Login.cshtml.cs b/Server/src/SOR.Website/Pages/Auth/Login.cshtml.cs index fd87e97..64eb392 100644 --- a/Server/src/SOR.Website/Pages/Auth/Login.cshtml.cs +++ b/Server/src/SOR.Website/Pages/Auth/Login.cshtml.cs @@ -1,116 +1,15 @@ namespace SOR.Website.Pages.Auth; -using System.ComponentModel.DataAnnotations; -using System.Security.Claims; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.AspNetCore.RateLimiting; -using Microsoft.EntityFrameworkCore; -using SOR.Database.Entities.Identity; /// -/// Handles player login via email + password. -/// -/// Security controls: -/// - [EnableRateLimiting]: 10 attempts per IP per 5 minutes. -/// - lockoutOnFailure: true in PasswordSignInAsync — Identity locks the account -/// after 5 failures, defeating unlimited brute-force. -/// - ReturnUrl validated with Url.IsLocalUrl before redirect — no open redirect. -/// - Anti-forgery token validated by Razor Pages on every POST (default behavior). -/// - Generic error message: does NOT confirm whether the email exists (no enumeration). -/// - SignInWithClaimsAsync adds the display_name custom claim so the nav bar can -/// show the player's handle without a DB round-trip per request. +/// Local password login is no longer used — all authentication is handled by Keycloak. +/// This page model exists only to redirect any bookmarked /auth/login URLs gracefully. +/// Program.cs also maps GET /auth/login → /auth/challenge as a belt-and-suspenders guard. /// -[EnableRateLimiting("auth-login")] -public sealed class LoginModel( - SignInManager signInManager, - UserManager userManager) : PageModel +public sealed class LoginModel : PageModel { - [BindProperty] - public InputModel Input { get; set; } = new(); - - // returnUrl is injected by ASP.NET Core's cookie auth middleware when it - // redirects an unauthenticated request to the login page. - [BindProperty(SupportsGet = true)] - public string? ReturnUrl { get; set; } - - public string? ErrorMessage { get; private set; } - - public sealed class InputModel - { - // Accepts either an email address or the player's in-game display name (handle). - [Required(ErrorMessage = "Username or email is required.")] - [MaxLength(254)] - public string UsernameOrEmail { get; set; } = string.Empty; - - [Required(ErrorMessage = "Password is required.")] - [DataType(DataType.Password)] - [MaxLength(128)] - public string Password { get; set; } = string.Empty; - - public bool RememberMe { get; set; } - } - - public IActionResult OnGet() - { - // Already signed in — send them where they were going. - if (User.Identity?.IsAuthenticated == true) - return SafeRedirect(ReturnUrl); - - return Page(); - } - - public async Task OnPostAsync() - { - if (!ModelState.IsValid) - return Page(); - - // Resolve account: try email first, then fall back to display name. - // We look up the user explicitly so we can use the TUser overload of - // PasswordSignInAsync — this lets us pass lockoutOnFailure correctly - // regardless of which identifier the player used. - var input = Input.UsernameOrEmail.Trim(); - var user = await userManager.FindByEmailAsync(input) - ?? await userManager.Users - .FirstOrDefaultAsync(u => u.DisplayName == input); - - if (user is not null) - { - var result = await signInManager.PasswordSignInAsync( - user, - Input.Password, - Input.RememberMe, - lockoutOnFailure: true); - - if (result.Succeeded) - { - // Embed display_name in the cookie so the nav bar shows the - // player's handle without a DB round-trip on every request. - var extraClaims = new[] - { - new Claim("display_name", user.DisplayName ?? user.Email ?? string.Empty), - }; - await signInManager.SignInWithClaimsAsync(user, Input.RememberMe, extraClaims); - return SafeRedirect(ReturnUrl); - } - - if (result.IsLockedOut) - { - ErrorMessage = "Too many failed attempts. Please try again later."; - return Page(); - } - } - - // Generic: does not confirm whether the identifier exists (prevents enumeration). - ErrorMessage = "Invalid username/email or password."; - return Page(); - } - - // Ensures the redirect target is local to this application. - // Url.IsLocalUrl rejects absolute URLs and protocol-relative URLs, - // preventing open redirect attacks where an attacker crafts a link like - // /auth/login?returnUrl=https://evil.com - private IActionResult SafeRedirect(string? url) - => Url.IsLocalUrl(url) ? LocalRedirect(url) : RedirectToPage("/Index"); + public IActionResult OnGet(string? returnUrl) + => Redirect("/auth/challenge" + (string.IsNullOrEmpty(returnUrl) ? "" : $"?returnUrl={Uri.EscapeDataString(returnUrl)}")); } diff --git a/Server/src/SOR.Website/Pages/Auth/Register.cshtml b/Server/src/SOR.Website/Pages/Auth/Register.cshtml index 7480314..d4475fb 100644 --- a/Server/src/SOR.Website/Pages/Auth/Register.cshtml +++ b/Server/src/SOR.Website/Pages/Auth/Register.cshtml @@ -1,71 +1,3 @@ @page -@model RegisterModel -@{ - ViewData["Title"] = "Create Account"; -} - -
-
-

Create Account

-

Begin your journey as a Channeler.

- -
-
- -
- - - -
- -
- - - - 3–32 characters. Letters, digits, spaces, hyphens, underscores. -
- -
- - - - At least 8 characters, including an uppercase letter, digit, and symbol. -
- -
- - - -
- -
- - - -
- - -
- - -
-
+@model SOR.Website.Pages.Auth.RegisterModel +@* This page is not rendered — the model redirects to /auth/challenge immediately. *@ diff --git a/Server/src/SOR.Website/Pages/Auth/Register.cshtml.cs b/Server/src/SOR.Website/Pages/Auth/Register.cshtml.cs index dc54bbb..2ff3aa1 100644 --- a/Server/src/SOR.Website/Pages/Auth/Register.cshtml.cs +++ b/Server/src/SOR.Website/Pages/Auth/Register.cshtml.cs @@ -1,114 +1,15 @@ namespace SOR.Website.Pages.Auth; -using System.ComponentModel.DataAnnotations; -using System.Security.Claims; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.AspNetCore.RateLimiting; -using SOR.Database.Entities.Identity; /// -/// Handles new player registration. -/// -/// Security controls: -/// - [EnableRateLimiting]: 5 registrations per IP per hour. -/// - Anti-forgery token validated on every POST. -/// - Generic error response: does NOT distinguish "email taken" from validation errors -/// so an attacker cannot probe whether an email is registered. -/// - DisplayName length and character restrictions prevent injection into downstream -/// systems that consume this value. -/// - Password strength is enforced by Identity (RequireDigit, RequireUppercase, etc.). -/// - CreatedAt set server-side — never from user input. +/// Local account management is no longer handled by this site — Keycloak owns all +/// registration, password reset, and email verification flows. +/// Redirects to the Keycloak-hosted login/registration page. /// -[EnableRateLimiting("auth-register")] -public sealed class RegisterModel( - UserManager userManager, - SignInManager signInManager) : PageModel +public sealed class RegisterModel : PageModel { - [BindProperty] - public InputModel Input { get; set; } = new(); - - public bool Success { get; private set; } - - public sealed class InputModel - { - [Required(ErrorMessage = "Email is required.")] - [EmailAddress(ErrorMessage = "Enter a valid email address.")] - [MaxLength(254)] - public string Email { get; set; } = string.Empty; - - [Required(ErrorMessage = "Display name is required.")] - [MinLength(3, ErrorMessage = "Display name must be at least 3 characters.")] - [MaxLength(32, ErrorMessage = "Display name cannot exceed 32 characters.")] - // Allow letters, digits, spaces, hyphens, underscores only. - // This prevents special characters that could cause issues in downstream display. - [RegularExpression(@"^[\w\- ]+$", - ErrorMessage = "Display name may only contain letters, digits, spaces, hyphens, and underscores.")] - public string DisplayName { get; set; } = string.Empty; - - [Required(ErrorMessage = "Password is required.")] - [MinLength(8, ErrorMessage = "Password must be at least 8 characters.")] - [MaxLength(128)] - [DataType(DataType.Password)] - public string Password { get; set; } = string.Empty; - - [Required(ErrorMessage = "Please confirm your password.")] - [DataType(DataType.Password)] - [Compare(nameof(Password), ErrorMessage = "Passwords do not match.")] - public string ConfirmPassword { get; set; } = string.Empty; - - [Range(typeof(bool), "true", "true", - ErrorMessage = "You must accept the terms and privacy policy.")] - public bool AcceptTerms { get; set; } - } - - public void OnGet() { } - - public async Task OnPostAsync() - { - if (!ModelState.IsValid) - return Page(); - - var account = new Account - { - UserName = Input.Email, // Identity uses UserName as the login key - Email = Input.Email, - DisplayName = Input.DisplayName.Trim(), - CreatedAt = DateTimeOffset.UtcNow, - RankScore = 1000, - }; - - var result = await userManager.CreateAsync(account, Input.Password); - - if (result.Succeeded) - { - // Sign in immediately with the display_name claim. - var claims = new[] { new Claim("display_name", account.DisplayName ?? string.Empty) }; - await signInManager.SignInWithClaimsAsync(account, isPersistent: false, claims); - return RedirectToPage("/Account/Index"); - } - - // Do NOT enumerate specific errors back to the user (e.g. "email already taken"). - // Instead surface a single generic message. Detailed validation errors (password - // strength, display name format) are acceptable — they don't expose account info. - // - // We do add Identity errors but filter out DuplicateEmail/DuplicateUserName to - // prevent account enumeration. - foreach (var error in result.Errors) - { - if (error.Code is "DuplicateEmail" or "DuplicateUserName") - { - // Generic message: attacker cannot learn whether the email is taken. - ModelState.AddModelError(string.Empty, - "Unable to create account. Please check your details and try again."); - } - else - { - ModelState.AddModelError(string.Empty, error.Description); - } - } - - return Page(); - } + public IActionResult OnGet() => Redirect("/auth/challenge"); + public IActionResult OnPost() => Redirect("/auth/challenge"); } diff --git a/Server/src/SOR.Website/Pages/Auth/ResetPassword.cshtml b/Server/src/SOR.Website/Pages/Auth/ResetPassword.cshtml index 08cb467..dea8bda 100644 --- a/Server/src/SOR.Website/Pages/Auth/ResetPassword.cshtml +++ b/Server/src/SOR.Website/Pages/Auth/ResetPassword.cshtml @@ -1,56 +1,3 @@ @page -@model ResetPasswordModel -@{ - ViewData["Title"] = "Reset Password"; -} - -
-
-

Reset Password

- - @if (Model.InvalidLink) - { - - Request Reset Link - } - else if (Model.Success) - { -
- Your password has been reset. You can now log in with your new password. -
- Log In - } - else - { -
- @* Token and email from the reset link are hidden — not displayed to user. *@ - - - -
- -
- - - -
- -
- - - -
- - -
- } -
-
+@model SOR.Website.Pages.Auth.ResetPasswordModel +@* This page is not rendered — the model redirects to /auth/challenge immediately. *@ diff --git a/Server/src/SOR.Website/Pages/Auth/ResetPassword.cshtml.cs b/Server/src/SOR.Website/Pages/Auth/ResetPassword.cshtml.cs index 5d3f383..8be0503 100644 --- a/Server/src/SOR.Website/Pages/Auth/ResetPassword.cshtml.cs +++ b/Server/src/SOR.Website/Pages/Auth/ResetPassword.cshtml.cs @@ -1,97 +1,15 @@ namespace SOR.Website.Pages.Auth; -using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.AspNetCore.RateLimiting; -using SOR.Database.Entities.Identity; /// -/// Validates the reset token and applies a new password. -/// -/// Security controls: -/// - [EnableRateLimiting]: 3 per IP per 15 minutes (shared with forgot-password policy). -/// - Anti-forgery token validated on POST. -/// - Token validated by Identity's built-in TOTP provider — single-use, time-limited. -/// - Generic error on invalid/expired token — no detail about why it failed. -/// - Email is supplied via query string from the reset link (not from user input). -/// It is bound server-side only for the lookup, not displayed back to the user -/// in a way that could introduce reflected content. -/// - Password must meet the same strength rules as registration (Identity enforces this). +/// Local account management is no longer handled by this site — Keycloak owns all +/// registration, password reset, and email verification flows. +/// Redirects to the Keycloak-hosted login/registration page. /// -[EnableRateLimiting("auth-reset")] -public sealed class ResetPasswordModel(UserManager userManager) : PageModel +public sealed class ResetPasswordModel : PageModel { - [BindProperty] - public InputModel Input { get; set; } = new(); - - public bool Success { get; private set; } - public bool InvalidLink { get; private set; } - - public sealed class InputModel - { - // These two come from the query string in the emailed link. - // They are not displayed to the user — only used server-side. - [Required] - public string Token { get; set; } = string.Empty; - - [Required] - [EmailAddress] - [MaxLength(254)] - public string Email { get; set; } = string.Empty; - - [Required(ErrorMessage = "New password is required.")] - [MinLength(8, ErrorMessage = "Password must be at least 8 characters.")] - [MaxLength(128)] - [DataType(DataType.Password)] - public string NewPassword { get; set; } = string.Empty; - - [Required(ErrorMessage = "Please confirm your new password.")] - [DataType(DataType.Password)] - [Compare(nameof(NewPassword), ErrorMessage = "Passwords do not match.")] - public string ConfirmPassword { get; set; } = string.Empty; - } - - public IActionResult OnGet([FromQuery] string? token, [FromQuery] string? email) - { - if (string.IsNullOrWhiteSpace(token) || string.IsNullOrWhiteSpace(email)) - { - InvalidLink = true; - return Page(); - } - - Input.Token = token; - Input.Email = email; - return Page(); - } - - public async Task OnPostAsync() - { - if (!ModelState.IsValid) - return Page(); - - var user = await userManager.FindByEmailAsync(Input.Email); - - // If the user doesn't exist, still show success (anti-enumeration). - if (user is null || user.IsAi) - { - Success = true; - return Page(); - } - - var result = await userManager.ResetPasswordAsync(user, Input.Token, Input.NewPassword); - - if (result.Succeeded) - { - Success = true; - return Page(); - } - - // Generic message — does not reveal whether the token expired, was already used, - // or the email was wrong. All failure modes look the same to the requester. - ModelState.AddModelError(string.Empty, - "This reset link is invalid or has expired. Please request a new one."); - return Page(); - } + public IActionResult OnGet() => Redirect("/auth/challenge"); + public IActionResult OnPost() => Redirect("/auth/challenge"); } diff --git a/Server/src/SOR.Website/Pages/Auth/VerifyEmail.cshtml b/Server/src/SOR.Website/Pages/Auth/VerifyEmail.cshtml index 0a0b6d7..31ae3c8 100644 --- a/Server/src/SOR.Website/Pages/Auth/VerifyEmail.cshtml +++ b/Server/src/SOR.Website/Pages/Auth/VerifyEmail.cshtml @@ -1,34 +1,3 @@ @page -@model VerifyEmailModel -@{ - ViewData["Title"] = "Verify Email"; -} - -
-
-

Email Verification

- - @if (Model.Success) - { -
- Your email has been verified. Your account is fully active. -
- Go to Account - } - else if (Model.AlreadyVerified) - { -
- Your email is already verified. -
- Go to Account - } - else - { - - Log In - } -
-
+@model SOR.Website.Pages.Auth.VerifyEmailModel +@* This page is not rendered — the model redirects to /auth/challenge immediately. *@ diff --git a/Server/src/SOR.Website/Pages/Auth/VerifyEmail.cshtml.cs b/Server/src/SOR.Website/Pages/Auth/VerifyEmail.cshtml.cs index b3656df..656b4dd 100644 --- a/Server/src/SOR.Website/Pages/Auth/VerifyEmail.cshtml.cs +++ b/Server/src/SOR.Website/Pages/Auth/VerifyEmail.cshtml.cs @@ -1,55 +1,15 @@ namespace SOR.Website.Pages.Auth; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using SOR.Database.Entities.Identity; /// -/// Confirms a player's email address via a one-time token link. -/// -/// Security controls: -/// - Token validated by Identity's built-in provider (single-use, time-limited). -/// - Generic error shown on failure — no detail about whether email or token was wrong. -/// - This page does not require authentication — players reach it by clicking a link -/// in their registration email before they're signed in. +/// Local account management is no longer handled by this site — Keycloak owns all +/// registration, password reset, and email verification flows. +/// Redirects to the Keycloak-hosted login/registration page. /// -public sealed class VerifyEmailModel(UserManager userManager) : PageModel +public sealed class VerifyEmailModel : PageModel { - public bool Success { get; private set; } - public bool AlreadyVerified { get; private set; } - public bool Failed { get; private set; } - - public async Task OnGetAsync( - [FromQuery] string? userId, - [FromQuery] string? token) - { - if (string.IsNullOrWhiteSpace(userId) || string.IsNullOrWhiteSpace(token)) - { - Failed = true; - return Page(); - } - - var user = await userManager.FindByIdAsync(userId); - if (user is null) - { - // Anti-enumeration: don't reveal that the userId is invalid. - Failed = true; - return Page(); - } - - if (user.EmailConfirmed) - { - AlreadyVerified = true; - return Page(); - } - - var result = await userManager.ConfirmEmailAsync(user, token); - if (result.Succeeded) - Success = true; - else - Failed = true; - - return Page(); - } + public IActionResult OnGet() => Redirect("/auth/challenge"); + public IActionResult OnPost() => Redirect("/auth/challenge"); } diff --git a/Server/src/SOR.Website/Program.cs b/Server/src/SOR.Website/Program.cs index 5b14dfd..2228be9 100644 --- a/Server/src/SOR.Website/Program.cs +++ b/Server/src/SOR.Website/Program.cs @@ -228,10 +228,21 @@ app.UseAuthorization(); app.MapGet("/auth/challenge", async (HttpContext ctx, [Microsoft.AspNetCore.Mvc.FromQuery] string? returnUrl) => { + // Validate returnUrl is local before trusting it — prevents open-redirect abuse + // where an attacker crafts /auth/challenge?returnUrl=https://evil.com and the + // user gets bounced there after a legitimate Keycloak login. + var safeReturn = IsLocalUrl(returnUrl) ? returnUrl! : "/"; await ctx.ChallengeAsync("Keycloak", - new AuthenticationProperties { RedirectUri = returnUrl ?? "/" }); + new AuthenticationProperties { RedirectUri = safeReturn }); }).AllowAnonymous(); +// Guard: old local-password auth routes no longer work (SignInManager is not registered). +// Redirect them to the Keycloak challenge so visitors get a working login flow instead of a 500. +app.MapGet("/auth/login", () => Results.Redirect("/auth/challenge")).AllowAnonymous(); +app.MapGet("/auth/register", () => Results.Redirect("/auth/challenge")).AllowAnonymous(); +app.MapGet("/auth/forgot-password",() => Results.Redirect("/auth/challenge")).AllowAnonymous(); +app.MapGet("/auth/reset-password", () => Results.Redirect("/auth/challenge")).AllowAnonymous(); + // Logout: signs out of the local cookie AND the Keycloak SSO session so the // player must re-authenticate on both the website and the webclient. app.MapPost("/auth/logout", async (HttpContext ctx) => @@ -253,6 +264,17 @@ await app.RunAsync(); // ── Helpers ─────────────────────────────────────────────────────────────────── +// Mirrors ASP.NET Core's Url.IsLocalUrl logic. +// Rejects absolute URLs (https://evil.com), protocol-relative URLs (//evil.com), +// and backslash variants (/\evil.com) that some parsers treat as path separators. +static bool IsLocalUrl(string? url) +{ + if (string.IsNullOrEmpty(url)) return false; + if (url[0] != '/') return false; + if (url.Length == 1) return true; + return url[1] != '/' && url[1] != (char)0x5C; // 0x5C = backslash +} + static async Task CheckOidcDiscoveryAsync(WebApplication app) { var opts = app.Services