Files
sor/Server/src/SOR.Website/Pages/Cards/Details.cshtml.cs
T
c972b8687e 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>
2026-04-22 19:51:04 -04:00

59 lines
1.9 KiB
C#

namespace SOR.Website.Pages.Cards;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using SOR.Database.Contexts;
using SOR.Database.Entities.Catalog;
using SOR.Database.Enums;
/// <summary>
/// Individual card detail page.
///
/// Security controls:
/// - Card ID is a GUID — cannot be manipulated to traverse to other resources.
/// - Only published, non-retired cards are shown; unpublished cards return 404.
/// - All card data rendered through Razor's auto-encoding (no Html.Raw).
/// </summary>
public sealed class DetailsModel(CatalogDbContext catalog) : PageModel
{
public CardDefinition? Card { get; private set; }
public IList<CardDefinition> RelatedCards { get; private set; } = [];
public async Task<IActionResult> OnGetAsync(Guid id)
{
Card = await catalog.CardDefinitions
.Include(c => c.Set)
.Include(c => c.Assets)
.Include(c => c.PreviousTier)
.Where(c => c.Id == id && c.IsPublished && !c.IsRetired && c.CardType != CardType.SpiritToken)
.AsNoTracking()
.FirstOrDefaultAsync();
if (Card is null)
return NotFound();
// Load related cards: same set, same type, different card
if (Card.SetId.HasValue)
{
RelatedCards = await catalog.CardDefinitions
.Where(c => c.SetId == Card.SetId
&& c.CardType == Card.CardType
&& c.Id != Card.Id
&& c.IsPublished
&& !c.IsRetired)
.OrderBy(c => c.Name)
.Take(6)
.AsNoTracking()
.ToListAsync();
}
ViewData["Title"] = Card.Name;
ViewData["MetaDescription"] = Card.Description.Length > 160
? Card.Description[..160]
: Card.Description;
return Page();
}
}