fix(api): protect local library path details #371

Merged
timothy merged 2 commits from codex/334-sensitive-local-paths into main 2026-07-16 19:16:52 +02:00
3 changed files with 23 additions and 1 deletions
@@ -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<RequiresAuthenticationAttribute>(inherit: true).Any() ||
action.GetCustomAttributes<RequiresAuthenticationAttribute>(inherit: true).Any();
private static bool IsApiAuthorizationFilterRegisteredGlobally()
{
var settings = new Dictionary<string, string?>
@@ -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<IActionResult> GetById(int id, CancellationToken cancellationToken)
+3 -1
View File
@@ -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