From 46c4714a1377d698f6b35879a276d8be8f11dfe7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 22 Oct 2026 21:54:18 -0500 Subject: require administrator role for dumps, check Dumpable option first --- .../Core/API/Controllers/ApplicationController.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/slskd/Core/API/Controllers/ApplicationController.cs') diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs index 70c260f6..b0051dbd 100644 --- a/src/slskd/Core/API/Controllers/ApplicationController.cs +++ b/src/slskd/Core/API/Controllers/ApplicationController.cs @@ -42,6 +42,7 @@ namespace slskd.Core.API using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Hosting; using Serilog; + using slskd.Authentication; /// /// Application. @@ -57,17 +58,20 @@ namespace slskd.Core.API IHostApplicationLifetime lifetime, IApplication application, IOptionsMonitor optionsMonitor, + OptionsAtStartup optionsAtStartup, IStateMonitor applicationStateMonitor) { Lifetime = lifetime; Application = application; OptionsMonitor = optionsMonitor; + OptionsAtStartup = optionsAtStartup; ApplicationStateMonitor = applicationStateMonitor; } private IApplication Application { get; } private IStateMonitor ApplicationStateMonitor { get; } private IOptionsMonitor OptionsMonitor { get; } + private OptionsAtStartup OptionsAtStartup { get; } private IHostApplicationLifetime Lifetime { get; } private ILogger Log { get; } = Serilog.Log.ForContext(); @@ -160,13 +164,23 @@ namespace slskd.Core.API [ApiExplorerSettings(IgnoreApi = true)] [HttpGet("dump")] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] public async Task DumpMemory() { - using var dumper = new Dumper(); - var file = await dumper.DumpAsync(); + if (OptionsAtStartup.Flags.Dumpable) + { + Log.Warning("Dumping application memory..."); + + using var dumper = new Dumper(); + var file = await dumper.DumpAsync(); + + Log.Warning("Dump complete"); + + return PhysicalFile(file, "application/octet-stream", "slskd.dmp"); + } - return PhysicalFile(file, "application/octet-stream", "slskd.dmp"); + Log.Warning("Unauthorized attempt to dump application memory; Flags.Dumpable is disabled"); + return Forbid(); } [ApiExplorerSettings(IgnoreApi = true)] -- cgit v1.2.3 From f7da9a79fd5de7e4dd675f279317cbea49cea851 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 22 Oct 2026 21:54:46 -0500 Subject: require r/w role for loopback --- src/slskd/Core/API/Controllers/ApplicationController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Core/API/Controllers/ApplicationController.cs') diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs index b0051dbd..a9630e5c 100644 --- a/src/slskd/Core/API/Controllers/ApplicationController.cs +++ b/src/slskd/Core/API/Controllers/ApplicationController.cs @@ -185,7 +185,7 @@ namespace slskd.Core.API [ApiExplorerSettings(IgnoreApi = true)] [HttpPost("loopback")] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.ReadWriteOrAdministrator)] public IActionResult Loopback([FromBody] object body) { Log.Information("Loopback POST: {Body}", body); -- cgit v1.2.3 From e20ccd6abd0e86006b7a66d10dd35d0212281cfb Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 22 Oct 2026 21:55:05 -0500 Subject: require admin for garbage collection --- src/slskd/Core/API/Controllers/ApplicationController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Core/API/Controllers/ApplicationController.cs') diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs index a9630e5c..84ddf063 100644 --- a/src/slskd/Core/API/Controllers/ApplicationController.cs +++ b/src/slskd/Core/API/Controllers/ApplicationController.cs @@ -154,7 +154,7 @@ namespace slskd.Core.API /// [ApiExplorerSettings(IgnoreApi = true)] [HttpPost("gc")] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] public IActionResult CollectGarbage() { Application.CollectGarbage(); -- cgit v1.2.3 From c6983ea67c974bf39b9df9aa0eeab292d3969012 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 22 Oct 2026 21:57:12 -0500 Subject: restrict forced version check to r/w --- src/slskd/Core/API/Controllers/ApplicationController.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/slskd/Core/API/Controllers/ApplicationController.cs') diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs index 84ddf063..c9af1296 100644 --- a/src/slskd/Core/API/Controllers/ApplicationController.cs +++ b/src/slskd/Core/API/Controllers/ApplicationController.cs @@ -137,11 +137,16 @@ namespace slskd.Core.API /// /// [HttpGet("version/latest")] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.Any)] public async Task CheckVersion([FromQuery] bool forceCheck = false) { if (forceCheck) { + if (!User.IsInRole(nameof(Role.ReadWrite)) && !User.IsInRole(nameof(Role.Administrator))) + { + return Forbid(); + } + await Application.CheckVersionAsync(); } -- cgit v1.2.3