diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-10-22 22:39:46 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-10-22 22:39:46 -0500 |
| commit | b2dcbac8e0b45dc7261b3b486e7392d27e6a04b7 (patch) | |
| tree | e6ce1f140196c035d3532d8a86343261b949f07d /src/slskd/Core/API | |
| parent | e6458e011c745eb0b0f6b0ce0474491381438178 (diff) | |
| parent | 6be4f40d3079089ec91d48b05400a1b92b8ca899 (diff) | |
| download | slskd-b2dcbac8e0b45dc7261b3b486e7392d27e6a04b7.tar.gz | |
Merge branch 'master' into fix/version-string-spacing
Diffstat (limited to 'src/slskd/Core/API')
5 files changed, 36 insertions, 13 deletions
diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs index 70c260f6..c9af1296 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; /// <summary> /// Application. @@ -57,17 +58,20 @@ namespace slskd.Core.API IHostApplicationLifetime lifetime, IApplication application, IOptionsMonitor<Options> optionsMonitor, + OptionsAtStartup optionsAtStartup, IStateMonitor<State> applicationStateMonitor) { Lifetime = lifetime; Application = application; OptionsMonitor = optionsMonitor; + OptionsAtStartup = optionsAtStartup; ApplicationStateMonitor = applicationStateMonitor; } private IApplication Application { get; } private IStateMonitor<State> ApplicationStateMonitor { get; } private IOptionsMonitor<Options> OptionsMonitor { get; } + private OptionsAtStartup OptionsAtStartup { get; } private IHostApplicationLifetime Lifetime { get; } private ILogger Log { get; } = Serilog.Log.ForContext<ApplicationController>(); @@ -133,11 +137,16 @@ namespace slskd.Core.API /// </summary> /// <returns></returns> [HttpGet("version/latest")] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.Any)] public async Task<IActionResult> CheckVersion([FromQuery] bool forceCheck = false) { if (forceCheck) { + if (!User.IsInRole(nameof(Role.ReadWrite)) && !User.IsInRole(nameof(Role.Administrator))) + { + return Forbid(); + } + await Application.CheckVersionAsync(); } @@ -150,7 +159,7 @@ namespace slskd.Core.API /// <returns></returns> [ApiExplorerSettings(IgnoreApi = true)] [HttpPost("gc")] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] public IActionResult CollectGarbage() { Application.CollectGarbage(); @@ -160,18 +169,28 @@ namespace slskd.Core.API [ApiExplorerSettings(IgnoreApi = true)] [HttpGet("dump")] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] public async Task<IActionResult> DumpMemory() { - using var dumper = new Dumper(); - var file = await dumper.DumpAsync(); + if (OptionsAtStartup.Flags.Dumpable) + { + Log.Warning("Dumping application memory..."); - return PhysicalFile(file, "application/octet-stream", "slskd.dmp"); + using var dumper = new Dumper(); + var file = await dumper.DumpAsync(); + + Log.Warning("Dump complete"); + + 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)] [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); diff --git a/src/slskd/Core/API/Controllers/DebugController.cs b/src/slskd/Core/API/Controllers/DebugController.cs index b5f6cd33..7f4dcafc 100644 --- a/src/slskd/Core/API/Controllers/DebugController.cs +++ b/src/slskd/Core/API/Controllers/DebugController.cs @@ -46,6 +46,7 @@ namespace slskd.Core.API [ApiController] [Produces("application/json")] [Consumes("application/json")] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] public class DebugController : ControllerBase { public DebugController(ISoulseekClient soulseekClient) @@ -56,7 +57,7 @@ namespace slskd.Core.API private ISoulseekClient Client { get; } [HttpGet("transfers")] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] [ProducesResponseType(typeof(Transfer), 200)] public IActionResult Transfers() { diff --git a/src/slskd/Core/API/Controllers/LogsController.cs b/src/slskd/Core/API/Controllers/LogsController.cs index a83e608c..c11d8ff3 100644 --- a/src/slskd/Core/API/Controllers/LogsController.cs +++ b/src/slskd/Core/API/Controllers/LogsController.cs @@ -51,6 +51,7 @@ namespace slskd.Core.API [ApiController] [Produces("application/json")] [Consumes("application/json")] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] public class LogsController : ControllerBase { public LogsController(FileService fileService) diff --git a/src/slskd/Core/API/Controllers/OptionsController.cs b/src/slskd/Core/API/Controllers/OptionsController.cs index 2d314b5f..e20017a8 100644 --- a/src/slskd/Core/API/Controllers/OptionsController.cs +++ b/src/slskd/Core/API/Controllers/OptionsController.cs @@ -53,6 +53,7 @@ namespace slskd.Core.API [ApiController] [Produces("application/json")] [Consumes("application/json")] + [Authorize(Roles = AuthRole.AdministratorOnly)] public class OptionsController : ControllerBase { public OptionsController( @@ -75,7 +76,7 @@ namespace slskd.Core.API /// </summary> /// <returns></returns> [HttpGet] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] [ProducesResponseType(typeof(Options), 200)] public IActionResult Current() { @@ -127,7 +128,7 @@ namespace slskd.Core.API /// <returns></returns> [HttpGet] [Route("startup")] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] [ProducesResponseType(typeof(Options), 200)] public IActionResult Startup() { @@ -221,7 +222,7 @@ namespace slskd.Core.API } [HttpPost] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] [Route("yaml/validate")] public IActionResult ValidateYamlFile([FromBody] string yaml) { diff --git a/src/slskd/Core/API/Controllers/ServerController.cs b/src/slskd/Core/API/Controllers/ServerController.cs index dd9c37d2..70adb858 100644 --- a/src/slskd/Core/API/Controllers/ServerController.cs +++ b/src/slskd/Core/API/Controllers/ServerController.cs @@ -48,6 +48,7 @@ namespace slskd.Core.API [ApiController] [Produces("application/json")] [Consumes("application/json")] + [Authorize(Roles = AuthRole.AdministratorOnly)] public class ServerController : ControllerBase { public ServerController( @@ -73,7 +74,7 @@ namespace slskd.Core.API /// <returns></returns> [HttpPut] [Route("")] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.ReadWriteOrAdministrator)] [ProducesResponseType(200)] [ProducesResponseType(StatusCodes.Status205ResetContent)] [ProducesResponseType(403)] @@ -109,7 +110,7 @@ namespace slskd.Core.API /// <returns></returns> [HttpDelete] [Route("")] - [Authorize(Policy = AuthPolicy.Any)] + [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.ReadWriteOrAdministrator)] [ProducesResponseType(204)] [ProducesResponseType(403)] public IActionResult Disconnect([FromBody] string message) |
