fix: isolate public cookies from legacy application authentication

This commit is contained in:
Nick Beckley 2026-11-27 23:00:56 +00:00
parent f620dc0623
commit 681edbd4c3
3 changed files with 12 additions and 1 deletions

View File

@ -4,6 +4,7 @@ using PlotDirector.Website.Data;
using PlotDirector.Website.Services; using PlotDirector.Website.Services;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
builder.Services.AddAntiforgery(options => options.Cookie.Name = "PlotDirectorWebsiteAntiforgery");
builder.Services.AddMemoryCache(); builder.Services.AddMemoryCache();
var protection = builder.Services.AddDataProtection().SetApplicationName("PlotDirector.Website"); var protection = builder.Services.AddDataProtection().SetApplicationName("PlotDirector.Website");
if (builder.Configuration["DataProtection:KeysPath"] is string keysPath) protection.PersistKeysToFileSystem(new DirectoryInfo(keysPath)); if (builder.Configuration["DataProtection:KeysPath"] is string keysPath) protection.PersistKeysToFileSystem(new DirectoryInfo(keysPath));

View File

@ -9,7 +9,7 @@ namespace PlotDirector.Website.Services;
// is bound to the signed-in subject, and is disposable on restart or graph change. // is bound to the signed-in subject, and is disposable on restart or graph change.
public sealed class WritingSolverResultContext(IMemoryCache cache) public sealed class WritingSolverResultContext(IMemoryCache cache)
{ {
private const string Cookie = "pd-solver-result"; private const string Cookie = "PlotDirectorWebsiteSolverResult";
private static readonly TimeSpan Lifetime = TimeSpan.FromHours(2); private static readonly TimeSpan Lifetime = TimeSpan.FromHours(2);
private sealed record Entry(string Version, SolverAnswer[] Answers); private sealed record Entry(string Version, SolverAnswer[] Answers);
private static string? Token(HttpContext context) => context.Request.Cookies[Cookie] is { Length: 64 } token private static string? Token(HttpContext context) => context.Request.Cookies[Cookie] is { Length: 64 } token

View File

@ -1,6 +1,14 @@
# Merge with the reviewed live PlotDirector configuration; do not enable two vhosts # Merge with the reviewed live PlotDirector configuration; do not enable two vhosts
# for the same host. Preserve existing maintenance, verification and ACME locations. # for the same host. Preserve existing maintenance, verification and ACME locations.
map $http_upgrade $plotdirector_website_upgrade { default upgrade; '' close; } map $http_upgrade $plotdirector_website_upgrade { default upgrade; '' close; }
map $cookie_PlotDirectorWebsiteAntiforgery $plotdirector_public_antiforgery {
default "PlotDirectorWebsiteAntiforgery=$cookie_PlotDirectorWebsiteAntiforgery;";
"" "";
}
map $cookie_PlotDirectorWebsiteSolverResult $plotdirector_public_solver {
default "PlotDirectorWebsiteSolverResult=$cookie_PlotDirectorWebsiteSolverResult;";
"" "";
}
server { server {
listen 80; listen [::]:80; listen 80; listen [::]:80;
server_name plotdirector.com www.plotdirector.com; server_name plotdirector.com www.plotdirector.com;
@ -43,6 +51,7 @@ server {
# contains the former application drawer controller name. # contains the former application drawer controller name.
location ~* ^/HelpDrawer/(?:Image|Article)$ { location ~* ^/HelpDrawer/(?:Image|Article)$ {
proxy_pass http://127.0.0.1:5004; proxy_pass http://127.0.0.1:5004;
proxy_set_header Cookie "$plotdirector_public_antiforgery$plotdirector_public_solver";
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
@ -67,6 +76,7 @@ server {
# Retain original public Help and solver URLs, including legacy help redirects. # Retain original public Help and solver URLs, including legacy help redirects.
location / { location / {
proxy_pass http://127.0.0.1:5004; proxy_pass http://127.0.0.1:5004;
proxy_set_header Cookie "$plotdirector_public_antiforgery$plotdirector_public_solver";
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;