diff --git a/Docs/Sprints/2026-11-03-overnight.md b/Docs/Sprints/2026-11-03-overnight.md index 03be9750..73c3a095 100644 --- a/Docs/Sprints/2026-11-03-overnight.md +++ b/Docs/Sprints/2026-11-03-overnight.md @@ -17,13 +17,13 @@ 2. Completed: B2 compact Locations drag controls and PWA width. 3. Completed: B3 clickable project/book covers and titles. 4. Completed: B4 retire obsolete Phase 1 Checklist safely. -5. In progress: C shared workspace resizing and maximisation, starting with Relationships reference. -6. D UX audit and repairs. -7. E functional reliability repairs. -8. F security and data integrity audit and safe repairs. -9. G regression expansion. -10. H public site and Writing Problem Solver SEO. -11. Final gates, safe Development deployment and handover. +5. Completed: C shared workspace resizing and maximisation. +6. Completed: targeted D UX audit and repairs. +7. Completed: E Floor Plans save reliability repairs. +8. Completed: F trusted-proxy scheme repair and export/restore access review. +9. Completed: G regression expansion and final full harness. +10. Completed: H public site and Writing Problem Solver SEO. +11. In progress: final gates, trusted-proxy follow-up Development deployment and handover. ## Improvements and evidence @@ -108,3 +108,21 @@ Verification: build passed; all-editor/four-theme browser/PWA maximise suite and Reproduced two data-loss risks in the real editor fixture: (1) a save redirected to a login HTML page was labelled Saved; (2) an older successful request marked edits made during that request Saved before their own autosave. Require a non-redirected explicit ok:true response, reject malformed/null JSON safely, retain block state on failure, and track layout revisions so older acknowledgements cannot clear newer edits. Protect browser navigation while layout changes are dirty, saving or failed; remove that listener on workspace disposal. Verification: both failures were reproduced by the new browser test before repair. Build passed (0 warnings/errors). Browser/PWA save tests passed for redirects, malformed/null payloads, server rejection, valid acknowledgement, preserved blocks, navigation protection and concurrent edits followed by their own autosave. All-editor resizing regression passed again. Full harness rerun in progress. Restore-visibility follow-up commit: 86509cb. + +## Current checkpoint + +- Eleven verified implementation/test commits through 2f99a3c; all deployed to Development as 2f99a3c-20261103205138. +- Deployed and published PlotLine.dll SHA-256: b846ccec583652930e60b85131bbf5f3f89dafa7f762a9c1a1c128588a8c4694. Deployed metadata: .NETCoreApp v10.0, 13,825,536 bytes. +- Local and public Development GETs: 200. Protected Locations route requires login (302). No recent service warning/error logs. +- Background-work gate passed immediately before restart. Application backup: /srv/apps/plotdirector-dev/current-before-2f99a3c-20261103205138. Configuration, uploads, App_Data, logs preserved. No database writes/migrations and no Production deployment. +- Full harness after Floor Plans repair passed. Read-only live mobile browser audit passed for 56 public pages (all 52 solutions plus homepage, tour, solver and browse): HTTP 200, no horizontal overflow at 390px and no unnamed anchor findings. +- A temporary-storage quota interrupted a publish. Removed only sprint-owned superseded/incomplete publish directories and republished successfully outside /tmp. The failed publish was never deployed. +- Current task: HTTPS proxy-scheme repair. Protected HTTPS route redirected via HTTP; nginx sends X-Forwarded-Proto but app did not consume it. Added default loopback-trusted, one-hop scheme handling without forwarded-host trust. Build passed (0 warnings/errors); full harness passed, including real cookie challenge middleware tests for trusted/untrusted proxies. +- Next action: confirm final harness, commit proxy fix, fresh Release publish, recheck idle background queues, deploy to Development, verify HTTPS login redirect and hashes, complete handover. +- Live authenticated screen verification has not been claimed: no reusable authenticated Development session was available. Full editor interaction checks use isolated real Razor fixtures; live route checks verify authentication redirects. + +### F follow-up — HTTPS login redirects behind the trusted proxy + +Live Development smoke testing reproduced an HTTPS protected route redirecting to http://dev.plotdirector.com/Account/Login. nginx already supplies X-Forwarded-Proto; added scheme-only forwarded-header handling before HTTPS/authentication middleware. Retained framework loopback-only proxy trust and one-hop limit; forwarded hosts remain ignored. Secure cookie policy is unchanged. + +Verification: solution build passed with 0 warnings/errors and full harness passed. Regression exercises actual forwarded-header and cookie authentication middleware, requiring HTTPS redirects for IPv4/IPv6 loopback proxies while rejecting scheme spoofing from an untrusted remote client and ignoring forwarded hosts. Development redeployment and live redirect verification pending. diff --git a/PlotLine.Tests/Program.cs b/PlotLine.Tests/Program.cs index 4ba122a6..ab124685 100644 --- a/PlotLine.Tests/Program.cs +++ b/PlotLine.Tests/Program.cs @@ -123,6 +123,7 @@ var tests = new (string Name, Action Test)[] ("Writing Solver anonymous state is protected, expires and rejects stale versions", WritingSolverTests.AnonymousState), ("Writing Solver scoring, multi-select, revision, fallback and graph routes", WritingSolverTests.RoutingAndRevision), ("Writing Solver import rejects invalid graphs and editorial identities", WritingSolverTests.Validation), + ("Login redirects respect only trusted loopback proxy schemes", TrustedProxySchemeTests.LoginRedirectScheme), ("Project export and restore access gates enforce author and ownership boundaries", ProjectAccessRegressionTests.FilterBoundaries), ("Retired checklist bookmarks redirect without report access", LegacyAcceptanceTests.RedirectsWithoutReporting), ("Ribbon operation identity and semantic icons stay consistent", RibbonPresentationTests.SemanticMetadata), diff --git a/PlotLine.Tests/TrustedProxySchemeTests.cs b/PlotLine.Tests/TrustedProxySchemeTests.cs new file mode 100644 index 00000000..0d1cc530 --- /dev/null +++ b/PlotLine.Tests/TrustedProxySchemeTests.cs @@ -0,0 +1,44 @@ +using System.Net; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using PlotLine.Services; + +internal static class TrustedProxySchemeTests +{ + public static void LoginRedirectScheme() => Run().GetAwaiter().GetResult(); + private static async Task Run() + { + using var services = new ServiceCollection().AddLogging().AddOptions() + .AddAuthentication("Test").AddCookie("Test", options => { + options.LoginPath = "/Account/Login"; + options.Cookie.SecurePolicy = CookieSecurePolicy.Always; + }).Services.BuildServiceProvider(); + var builder = new ApplicationBuilder(services); + builder.UseTrustedProxyScheme(); + builder.UseAuthentication(); + builder.Run(context => context.ChallengeAsync("Test")); + var pipeline = builder.Build(); + foreach (var (remote, forwarded, expected) in new[] { + (IPAddress.Loopback, "https", "https"), + (IPAddress.IPv6Loopback, "https", "https"), + (IPAddress.Loopback, "http", "http"), + (IPAddress.Parse("203.0.113.10"), "https", "http") + }) + { + using var requestScope = services.CreateScope(); + var context = new DefaultHttpContext { RequestServices = requestScope.ServiceProvider }; + context.Connection.RemoteIpAddress = remote; + context.Request.Scheme = "http"; + context.Request.Host = new HostString("dev.plotdirector.test"); + context.Request.Path = "/private"; + context.Request.Headers["X-Forwarded-Proto"] = forwarded; + context.Request.Headers["X-Forwarded-Host"] = "untrusted.example"; + await pipeline(context); + var location = context.Response.Headers.Location.ToString(); + if (context.Response.StatusCode != 302 || !location.StartsWith(expected + "://dev.plotdirector.test/Account/Login?", StringComparison.Ordinal)) + throw new Exception("Login redirects must preserve the trusted proxy scheme and ignore untrusted forwarded headers."); + } + } +} diff --git a/PlotLine/Program.cs b/PlotLine/Program.cs index dbdb9560..e3bfbee7 100644 --- a/PlotLine/Program.cs +++ b/PlotLine/Program.cs @@ -302,6 +302,8 @@ public class Program var app = builder.Build(); + app.UseTrustedProxyScheme(); + if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); diff --git a/PlotLine/Services/TrustedProxyScheme.cs b/PlotLine/Services/TrustedProxyScheme.cs new file mode 100644 index 00000000..a2c1256c --- /dev/null +++ b/PlotLine/Services/TrustedProxyScheme.cs @@ -0,0 +1,14 @@ +using Microsoft.AspNetCore.HttpOverrides; + +namespace PlotLine.Services; + +public static class TrustedProxyScheme +{ + public static IApplicationBuilder UseTrustedProxyScheme(this IApplicationBuilder app) => + // Keep the framework's loopback proxy trust and one-hop limit. Do not + // accept forwarded hosts or broaden trust to arbitrary remote clients. + app.UseForwardedHeaders(new ForwardedHeadersOptions + { + ForwardedHeaders = ForwardedHeaders.XForwardedProto + }); +}