diff --git a/ErsatzTV.Tests/Controllers/ApiControllerSecurityTests.cs b/ErsatzTV.Tests/Controllers/ApiControllerSecurityTests.cs index a1510a59b..ed505ee3d 100644 --- a/ErsatzTV.Tests/Controllers/ApiControllerSecurityTests.cs +++ b/ErsatzTV.Tests/Controllers/ApiControllerSecurityTests.cs @@ -118,6 +118,20 @@ public class ApiControllerSecurityTests } } + [Test] + public void Local_Library_Detail_Should_Require_Authentication_While_Catalog_List_Remains_Opt_Out() + { + MethodInfo detailAction = typeof(LocalLibrariesController).GetMethod(nameof(LocalLibrariesController.GetById)) + ?? throw new AssertionException($"Missing action {nameof(LocalLibrariesController.GetById)}"); + MethodInfo listAction = typeof(LocalLibrariesController).GetMethod(nameof(LocalLibrariesController.GetAll)) + ?? throw new AssertionException($"Missing action {nameof(LocalLibrariesController.GetAll)}"); + + EffectiveRequiresAuthentication(typeof(LocalLibrariesController), detailAction) + .ShouldBeTrue("local-library detail exposes server filesystem paths and must stay authenticated"); + EffectiveRequiresAuthentication(typeof(LocalLibrariesController), listAction) + .ShouldBeFalse("the ordinary local-library catalog should retain the read-auth opt-out"); + } + [Test] public void ScannerController_Should_Be_Localhost_Only() { @@ -131,6 +145,10 @@ public class ApiControllerSecurityTests private static bool IsGloballyProtected() => ApiAuthorizationFilterIsGlobal; + private static bool EffectiveRequiresAuthentication(Type controllerType, MethodInfo action) => + controllerType.GetCustomAttributes(inherit: true).Any() || + action.GetCustomAttributes(inherit: true).Any(); + private static bool IsApiAuthorizationFilterRegisteredGlobally() { var settings = new Dictionary diff --git a/ErsatzTV/Controllers/Api/LocalLibrariesController.cs b/ErsatzTV/Controllers/Api/LocalLibrariesController.cs index a7ae9944a..d6ad63d31 100644 --- a/ErsatzTV/Controllers/Api/LocalLibrariesController.cs +++ b/ErsatzTV/Controllers/Api/LocalLibrariesController.cs @@ -7,6 +7,7 @@ using ErsatzTV.Core.Api.MediaSources; using ErsatzTV.Core.Interfaces.Locking; using ErsatzTV.Core.Interfaces.Repositories; using ErsatzTV.Extensions; +using ErsatzTV.Filters; using MediatR; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -40,6 +41,7 @@ public class LocalLibrariesController( [HttpGet("/api/v1/libraries/local/{id:int}", Name = "GetLocalLibrary")] [Tags("Libraries")] [EndpointSummary("Get a local library by id")] + [RequiresAuthentication] [ProducesResponseType(typeof(LocalLibraryDetailResponseModel), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] public async Task GetById(int id, CancellationToken cancellationToken) diff --git a/docs/api-conventions.md b/docs/api-conventions.md index b22636aba..013015dd7 100644 --- a/docs/api-conventions.md +++ b/docs/api-conventions.md @@ -625,7 +625,9 @@ OpenAPI generation, so the spec can't drift). When you add an endpoint: - **Sensitive-read GETs** that disclose secrets/paths or trigger work must carry `[RequiresAuthentication]` (renamed from `[RequiresApiKey]`) so they stay gated even if an operator sets `Api:RequireKeyForReads=false`. A valid session satisfies this tier just as the key does. Current tier: `Troubleshoot`/`Logs`/`Settings`/ - `Maintenance`. `ApiControllerSecurityTests` asserts this reflectively. + `Maintenance`, plus local-library detail (`GET /api/v1/libraries/local/{id}`), whose response contains + server filesystem paths. The ordinary local-library list remains in the catalog-read opt-out tier. + `ApiControllerSecurityTests` asserts these boundaries reflectively. - **Internal loopback callbacks** (the scanner's `/api/v1/scan/*`) and the **`/api/v1/auth/*` surface itself** use `[SkipApiAuthorization]` (renamed from `[SkipApiKeyAuthorization]`). The scanner adds `[LocalhostOnly]`; the auth surface must be reachable before a caller is authenticated, and its one sensitive action