fix(api): protect local library path details
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 7s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 8s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 5m30s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 3m28s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 55s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 4m41s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 9m58s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 7s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 8s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 5m30s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 3m28s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 55s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 4m41s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 9m58s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Fixes #334 Co-Authored-By: OpenAI Codex <codex@openai.com>
This commit is contained in:
@@ -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)}");
|
||||
|
||||
detailAction.GetCustomAttributes<RequiresAuthenticationAttribute>(inherit: true).Any()
|
||||
.ShouldBeTrue("local-library detail exposes server filesystem paths and must stay authenticated");
|
||||
listAction.GetCustomAttributes<RequiresAuthenticationAttribute>(inherit: true).Any()
|
||||
.ShouldBeFalse("the ordinary local-library catalog should retain the read-auth opt-out");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ScannerController_Should_Be_Localhost_Only()
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user