Exercise project export and restore authorisation boundaries
This commit is contained in:
parent
ab5325dfd9
commit
ba33b698cf
@ -57,7 +57,7 @@ Verification: solution build passed; rendered Razor browser regression passed fo
|
||||
|
||||
Confirmed the only application caller of the legacy aggregate report was Acceptance/Phase1. Removed its overview command, view, exclusive service, repository, model/view model and DI registrations. Kept the authenticated legacy action as a redirect to Projects/Details (or Projects/Index without a positive ID), so standard project authorisation handles bookmarks. Historical SQL migration and database objects remain unchanged; no tables or data removed.
|
||||
|
||||
Security finding fixed by retirement: the old service forwarded a supplied project ID even when absent from the user's project list; its procedure aggregates by project without a user parameter. No live cross-user query was performed.
|
||||
Security finding clarified during the later filter audit: the global ProjectAccessFilter already rejected supplied foreign project IDs. The old service's remaining unsafe path was an authenticated account with no projects and no projectId: it forwarded null to the procedure, which aggregates across all projects when the ID is null. Retirement removes that fallback. No live cross-user query was performed.
|
||||
|
||||
Verification: build passed (0 warnings/errors), full harness passed including bookmark routing/authentication regression. B3 commit: 77332a2. Initial new-test build failed because a top-level harness helper shadows Attribute; corrected to System.Attribute and reran successfully.
|
||||
|
||||
@ -82,3 +82,9 @@ Explicit B/C improvements are implemented and committed. Next: targeted broader
|
||||
Reproduced browser overflow at 390px: a 360px form had 369px scroll width because the image uploader required 220px beside a fixed portrait. Allowed the shared image editor to wrap, with a shrinkable controls column. Fixed form measures 360px/360px; restoring the old CSS reproduces 360px/369px. Replaced the browser test's accepted-overflow diagnostic with a no-overflow assertion.
|
||||
|
||||
Verification: existing record-workspaces browser suite passed for nine real Razor forms, browser/PWA actions, responsive widths (1920/1440/800/390), validation, original POST handling, six themes and stable first paint. Full harness after C2 passed (exit 0). C2 commit: d7ae6e2.
|
||||
|
||||
### F/G — Export and restore permission regression coverage
|
||||
|
||||
Traced global ProjectAccessFilter and current-user access service before evaluating repository calls. Existing export and restore controllers are guarded by the global filter; Maps also checks access explicitly. Added behavioural tests that run the real filter and access service against an isolated repository boundary: reject foreign projects and scene exports, reject collaborator owner-only backup export, reject foreign restore-point download/restore/delete, preserve valid collaborator reads, propagate current author, and reject anonymous/invalid identities without querying data. No permission rules changed.
|
||||
|
||||
Verification: solution build and full executable harness passed. Corrected B4 security analysis above after tracing the global filter; the retired null-project aggregate fallback was the remaining issue. D1 commit: ab5325d.
|
||||
|
||||
@ -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),
|
||||
("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),
|
||||
("Maps Story projects canonical hierarchy, sequence, journeys and evidence without changing geography", MapStoryTests.ProjectionAndEvidence),
|
||||
|
||||
71
PlotLine.Tests/ProjectAccessRegressionTests.cs
Normal file
71
PlotLine.Tests/ProjectAccessRegressionTests.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using PlotLine.Services;
|
||||
|
||||
internal static class ProjectAccessRegressionTests
|
||||
{
|
||||
private sealed class User(int? id) : ICurrentUserService
|
||||
{
|
||||
public int? UserId => id;
|
||||
public string? Email => null;
|
||||
public string? DisplayName => null;
|
||||
public bool IsAuthenticated => id.HasValue;
|
||||
}
|
||||
private sealed class Repository : IProjectAccessRepository
|
||||
{
|
||||
public List<(string Type, int Id, int User)> Calls { get; } = [];
|
||||
public Task<bool> UserCanAccessProjectAsync(int projectId, int userId)
|
||||
{
|
||||
Calls.Add(("Project", projectId, userId));
|
||||
return Task.FromResult(projectId == 7 && userId == 4);
|
||||
}
|
||||
public Task<bool> UserCanOwnProjectAsync(int projectId, int userId)
|
||||
{
|
||||
Calls.Add(("Owner", projectId, userId));
|
||||
return Task.FromResult(false); // This author is a collaborator.
|
||||
}
|
||||
public Task<bool> UserCanAccessEntityAsync(string entityType, int entityId, int userId)
|
||||
{
|
||||
Calls.Add((entityType, entityId, userId));
|
||||
return Task.FromResult(entityId == 23 && userId == 4);
|
||||
}
|
||||
}
|
||||
public static void FilterBoundaries() => Run().GetAwaiter().GetResult();
|
||||
private static async Task Run()
|
||||
{
|
||||
var repo = new Repository();
|
||||
var user = new User(4);
|
||||
var service = new ProjectAccessService(repo, user);
|
||||
var filter = new ProjectAccessFilter(service, user);
|
||||
async Task Check(string controller, string action, Dictionary<string, object?> arguments, bool allowed, string expectedType)
|
||||
{
|
||||
repo.Calls.Clear();
|
||||
var actionContext = new ActionContext(new DefaultHttpContext(), new RouteData(), new ControllerActionDescriptor { ControllerName = controller, ActionName = action });
|
||||
var filters = new List<IFilterMetadata>();
|
||||
var context = new ActionExecutingContext(actionContext, filters, arguments, new object());
|
||||
var called = false;
|
||||
await filter.OnActionExecutionAsync(context, () => { called = true; return Task.FromResult(new ActionExecutedContext(actionContext, filters, new object())); });
|
||||
if (called != allowed || (!allowed && context.Result is not NotFoundResult))
|
||||
throw new Exception($"{controller}/{action} must enforce access before controller execution.");
|
||||
if (!repo.Calls.Any(call => call.Type == expectedType) || repo.Calls.Any(call => call.User != 4))
|
||||
throw new Exception("Access must resolve the expected entity under the current author.");
|
||||
}
|
||||
await Check("Projects", "Details", new() { ["id"] = 98 }, false, "Project");
|
||||
await Check("Projects", "Details", new() { ["id"] = 7 }, true, "Project");
|
||||
await Check("Exports", "ProjectBackup", new() { ["projectId"] = 7 }, false, "Owner");
|
||||
await Check("Exports", "SceneBrief", new() { ["id"] = 98 }, false, "Scene");
|
||||
await Check("Exports", "SceneBrief", new() { ["id"] = 23 }, true, "Scene");
|
||||
await Check("ProjectRestorePoints", "Download", new() { ["projectId"] = 7, ["id"] = 98 }, false, "ProjectRestorePoint");
|
||||
await Check("ProjectRestorePoints", "Restore", new() { ["projectId"] = 7, ["id"] = 98 }, false, "ProjectRestorePoint");
|
||||
await Check("ProjectRestorePoints", "Delete", new() { ["projectId"] = 7, ["id"] = 98 }, false, "ProjectRestorePoint");
|
||||
repo.Calls.Clear();
|
||||
var anonymous = new ProjectAccessService(repo, new User(null));
|
||||
if (await anonymous.CanAccessProjectAsync(7) || await anonymous.CanAccessEntityAsync("Scene", 23)
|
||||
|| await anonymous.CanOwnProjectAsync(7) || await service.CanAccessProjectAsync(0)
|
||||
|| await service.CanAccessEntityAsync("Scene", -1) || repo.Calls.Count != 0)
|
||||
throw new Exception("Anonymous and invalid identities must fail closed before querying data.");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user