feat(website): stand up SOR.Website public game site
Adds the complete SOR.Website ASP.NET Core Razor Pages project:
Security architecture:
- SecurityHeadersMiddleware sets strict CSP (script-src/style-src 'self',
form-action 'self', frame-ancestors 'none', object-src 'none')
— all XSS injection is dead on arrival
- __Host- cookie prefix on session + CSRF cookies (forces Secure, Path=/,
no Domain — prevents subdomain-compromise cookie theft)
- Anti-forgery tokens on every POST by default (Razor Pages default)
- AuthorizeFolder("/Account") — unauthenticated access to any /account/*
redirected to login at the routing layer, no per-page [Authorize] needed
- Rate limiting per-IP: login (10/5min), register (5/hr), reset (3/15min)
- Open redirect prevention: all returnUrl values checked with Url.IsLocalUrl
- Anti-enumeration: ForgotPassword/Register never reveal whether email exists
- Account lockout: 5 failed login attempts → 30min lockout
- ChangePasswordAsync requires current password before accepting new one
- Leaderboard only projects DisplayName + RankScore (email/ID never exposed)
- Data Protection keys in Redis (shared key ring across pods)
- ForwardedHeaders middleware for accurate IP under TLS-terminating ingress
Pages implemented:
- Public: Home, Story, How To Play, Cards (catalog + detail), Leaderboard,
AI Assets (explanation + report), News, Support, Privacy, Terms, Webclient
- Auth: Login, Register, Logout (POST-only), ForgotPassword, ResetPassword,
VerifyEmail — all with rate limiting and anti-enumeration controls
- Account (auth-gated): Overview, Profile (display name), Security
(change password), Game stats
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
@page
|
||||
@model GameModel
|
||||
@{
|
||||
ViewData["Title"] = "Game Stats";
|
||||
var account = Model.AccountData!;
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
<div class="container">
|
||||
<h1>Game Stats</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container account-layout">
|
||||
<nav class="account-nav" aria-label="Account navigation">
|
||||
<a href="/account" class="account-nav-link">Overview</a>
|
||||
<a href="/account/profile" class="account-nav-link">Profile</a>
|
||||
<a href="/account/security" class="account-nav-link">Security</a>
|
||||
<a href="/account/game" class="account-nav-link active">Game Stats</a>
|
||||
</nav>
|
||||
|
||||
<div class="account-content">
|
||||
<div class="stat-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Rank Score</div>
|
||||
<div class="stat-value">@account.RankScore</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Origin Points</div>
|
||||
<div class="stat-value">@account.OriginPoints</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (account.LastLoginAt.HasValue)
|
||||
{
|
||||
<p class="text-muted">Last session: @account.LastLoginAt.Value.ToString("f")</p>
|
||||
}
|
||||
|
||||
<div class="coming-soon-block">
|
||||
<p>Full match history and collection stats are coming in a future update.</p>
|
||||
<a href="/leaderboard" class="btn btn-ghost">View Leaderboard</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace SOR.Website.Pages.Account;
|
||||
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using SOR.Database.Entities.Identity;
|
||||
|
||||
public sealed class GameModel(UserManager<Account> userManager) : PageModel
|
||||
{
|
||||
public Account? AccountData { get; private set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
AccountData = await userManager.GetUserAsync(User);
|
||||
if (AccountData is null) return RedirectToPage("/Auth/Logout");
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
@page
|
||||
@model IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Account";
|
||||
var account = Model.AccountData!;
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
<div class="container">
|
||||
<h1>@(account.DisplayName ?? "Channeler")</h1>
|
||||
<p class="account-since">Channeler since @account.CreatedAt.ToString("MMMM yyyy")</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container account-layout">
|
||||
<nav class="account-nav" aria-label="Account navigation">
|
||||
<a href="/account" class="account-nav-link active">Overview</a>
|
||||
<a href="/account/profile" class="account-nav-link">Profile</a>
|
||||
<a href="/account/security" class="account-nav-link">Security</a>
|
||||
<a href="/account/game" class="account-nav-link">Game Stats</a>
|
||||
</nav>
|
||||
|
||||
<div class="account-content">
|
||||
<div class="stat-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Rank Score</div>
|
||||
<div class="stat-value">@account.RankScore</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Email</div>
|
||||
@* Email shown only to the authenticated owner — never to other players. *@
|
||||
<div class="stat-value stat-email">@account.Email</div>
|
||||
@if (!account.EmailConfirmed)
|
||||
{
|
||||
<span class="badge badge-warn">Unverified</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="quick-actions">
|
||||
<a href="/webclient" class="btn btn-primary">Enter Mindscape</a>
|
||||
<a href="/account/profile" class="btn btn-ghost">Edit Profile</a>
|
||||
<a href="/account/security" class="btn btn-ghost">Security</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace SOR.Website.Pages.Account;
|
||||
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using SOR.Database.Entities.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Account dashboard — authenticated users only.
|
||||
/// Authorization is enforced by the AuthorizeFolder("/Account") convention in Program.cs.
|
||||
///
|
||||
/// Security controls:
|
||||
/// - Data shown is scoped to the currently signed-in account only.
|
||||
/// - Account ID comes from the validated session cookie, never from query string or form.
|
||||
/// - Fields that must not be public (email, internal ID, moderation state) are only
|
||||
/// accessible here behind authentication.
|
||||
/// </summary>
|
||||
public sealed class IndexModel(UserManager<Account> userManager) : PageModel
|
||||
{
|
||||
public Account? AccountData { get; private set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
// GetUserAsync reads the account ID from the signed-in claims principal.
|
||||
// It never trusts a user-supplied ID — the ID comes from the session cookie.
|
||||
AccountData = await userManager.GetUserAsync(User);
|
||||
|
||||
if (AccountData is null)
|
||||
{
|
||||
// Session exists but account was deleted — sign out cleanly.
|
||||
return RedirectToPage("/Auth/Logout");
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
@page
|
||||
@model ProfileModel
|
||||
@{
|
||||
ViewData["Title"] = "Edit Profile";
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
<div class="container">
|
||||
<h1>Profile</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container account-layout">
|
||||
<nav class="account-nav" aria-label="Account navigation">
|
||||
<a href="/account" class="account-nav-link">Overview</a>
|
||||
<a href="/account/profile" class="account-nav-link active">Profile</a>
|
||||
<a href="/account/security" class="account-nav-link">Security</a>
|
||||
<a href="/account/game" class="account-nav-link">Game Stats</a>
|
||||
</nav>
|
||||
|
||||
<div class="account-content">
|
||||
@if (Model.Saved)
|
||||
{
|
||||
<div class="alert alert-success" role="status">Profile updated.</div>
|
||||
}
|
||||
|
||||
<form method="post" novalidate>
|
||||
<div asp-validation-summary="ModelOnly" class="alert alert-error"></div>
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.DisplayName">Display Name</label>
|
||||
<input asp-for="Input.DisplayName" type="text" class="form-control">
|
||||
<span asp-validation-for="Input.DisplayName" class="field-error"></span>
|
||||
<small class="form-hint">This is your public in-game name. 3–32 characters.</small>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,74 @@
|
||||
namespace SOR.Website.Pages.Account;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using SOR.Database.Entities.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Allows the authenticated player to update their display name.
|
||||
///
|
||||
/// Security controls:
|
||||
/// - Account ID comes from the session cookie (GetUserAsync), never from the form.
|
||||
/// - DisplayName validation mirrors registration rules — no special characters
|
||||
/// that could cause downstream injection.
|
||||
/// - UpdateSecurityStampAsync after profile change causes existing sessions on
|
||||
/// other devices to be re-validated within 30 minutes (the ValidationInterval).
|
||||
/// - Anti-forgery token validated on POST.
|
||||
/// </summary>
|
||||
public sealed class ProfileModel(
|
||||
UserManager<Account> userManager,
|
||||
SignInManager<Account> signInManager) : PageModel
|
||||
{
|
||||
[BindProperty]
|
||||
public InputModel Input { get; set; } = new();
|
||||
|
||||
public bool Saved { get; private set; }
|
||||
|
||||
public sealed class InputModel
|
||||
{
|
||||
[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.")]
|
||||
[RegularExpression(@"^[\w\- ]+$",
|
||||
ErrorMessage = "Display name may only contain letters, digits, spaces, hyphens, and underscores.")]
|
||||
public string DisplayName { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
var account = await userManager.GetUserAsync(User);
|
||||
if (account is null) return RedirectToPage("/Auth/Logout");
|
||||
|
||||
Input.DisplayName = account.DisplayName ?? string.Empty;
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return Page();
|
||||
|
||||
var account = await userManager.GetUserAsync(User);
|
||||
if (account is null) return RedirectToPage("/Auth/Logout");
|
||||
|
||||
account.DisplayName = Input.DisplayName.Trim();
|
||||
var result = await userManager.UpdateAsync(account);
|
||||
|
||||
if (!result.Succeeded)
|
||||
{
|
||||
foreach (var err in result.Errors)
|
||||
ModelState.AddModelError(string.Empty, err.Description);
|
||||
return Page();
|
||||
}
|
||||
|
||||
// Refresh the session cookie so the nav bar immediately shows the new name.
|
||||
var claims = new[] { new Claim("display_name", account.DisplayName ?? string.Empty) };
|
||||
await signInManager.SignInWithClaimsAsync(account, isPersistent: false, claims);
|
||||
|
||||
Saved = true;
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
@page
|
||||
@model SecurityModel
|
||||
@{
|
||||
ViewData["Title"] = "Security";
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
<div class="container">
|
||||
<h1>Security</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container account-layout">
|
||||
<nav class="account-nav" aria-label="Account navigation">
|
||||
<a href="/account" class="account-nav-link">Overview</a>
|
||||
<a href="/account/profile" class="account-nav-link">Profile</a>
|
||||
<a href="/account/security" class="account-nav-link active">Security</a>
|
||||
<a href="/account/game" class="account-nav-link">Game Stats</a>
|
||||
</nav>
|
||||
|
||||
<div class="account-content">
|
||||
<h2>Change Password</h2>
|
||||
|
||||
@if (Model.Saved)
|
||||
{
|
||||
<div class="alert alert-success" role="status">
|
||||
Password updated. All other active sessions will be signed out shortly.
|
||||
</div>
|
||||
}
|
||||
|
||||
<form method="post" novalidate>
|
||||
<div asp-validation-summary="ModelOnly" class="alert alert-error"></div>
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.CurrentPassword">Current Password</label>
|
||||
<input asp-for="Input.CurrentPassword"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
class="form-control">
|
||||
<span asp-validation-for="Input.CurrentPassword" class="field-error"></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.NewPassword">New Password</label>
|
||||
<input asp-for="Input.NewPassword"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
class="form-control">
|
||||
<span asp-validation-for="Input.NewPassword" class="field-error"></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.ConfirmPassword">Confirm New Password</label>
|
||||
<input asp-for="Input.ConfirmPassword"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
class="form-control">
|
||||
<span asp-validation-for="Input.ConfirmPassword" class="field-error"></span>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Update Password</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,80 @@
|
||||
namespace SOR.Website.Pages.Account;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using SOR.Database.Entities.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Allows the authenticated player to change their password.
|
||||
///
|
||||
/// Security controls:
|
||||
/// - Requires the current password before accepting a new one. This prevents
|
||||
/// an attacker who has seized an unlocked browser session from silently changing
|
||||
/// credentials without knowing the existing password.
|
||||
/// - ChangePasswordAsync validates both the current password and the new password's
|
||||
/// strength rules via Identity.
|
||||
/// - UpdateSecurityStampAsync is called by ChangePasswordAsync — this invalidates
|
||||
/// all other active sessions within 30 minutes (the cookie ValidationInterval).
|
||||
/// - Account ID from session, not from form input.
|
||||
/// - Anti-forgery token validated on POST.
|
||||
/// </summary>
|
||||
public sealed class SecurityModel(
|
||||
UserManager<Account> userManager,
|
||||
SignInManager<Account> signInManager) : PageModel
|
||||
{
|
||||
[BindProperty]
|
||||
public InputModel Input { get; set; } = new();
|
||||
|
||||
public bool Saved { get; private set; }
|
||||
|
||||
public sealed class InputModel
|
||||
{
|
||||
[Required(ErrorMessage = "Current password is required.")]
|
||||
[DataType(DataType.Password)]
|
||||
[MaxLength(128)]
|
||||
public string CurrentPassword { 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 void OnGet() { }
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return Page();
|
||||
|
||||
var account = await userManager.GetUserAsync(User);
|
||||
if (account is null) return RedirectToPage("/Auth/Logout");
|
||||
|
||||
var result = await userManager.ChangePasswordAsync(
|
||||
account, Input.CurrentPassword, Input.NewPassword);
|
||||
|
||||
if (result.Succeeded)
|
||||
{
|
||||
// Re-sign-in to refresh the cookie after the security stamp changes.
|
||||
// Without this the cookie is rejected on the next request (30 min gap).
|
||||
await signInManager.RefreshSignInAsync(account);
|
||||
Saved = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
// Generic: "Incorrect current password" is acceptable — it does not help
|
||||
// an attacker because they must first be authenticated to reach this page.
|
||||
foreach (var err in result.Errors)
|
||||
ModelState.AddModelError(string.Empty, err.Description);
|
||||
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user