diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-10-22 22:39:13 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-10-22 22:39:13 -0500 |
| commit | 6be4f40d3079089ec91d48b05400a1b92b8ca899 (patch) | |
| tree | b022b5290a792a6bfea928315f06c359e86e8b5a /src/slskd/Core/API/Controllers/ApplicationController.cs | |
| parent | 4b84358f9ee5074873b4f0cc1030c97b10154e46 (diff) | |
| parent | 757c21eb1eb9c88ad46b789561f5dc5a6c7488eb (diff) | |
| download | slskd-6be4f40d3079089ec91d48b05400a1b92b8ca899.tar.gz | |
Merge pull request #1905 from slskd/dumps
Require explicit opt-in for run-time application memory dumps, adjust access level of several core API endpoints
Diffstat (limited to 'src/slskd/Core/API/Controllers/ApplicationController.cs')
| -rw-r--r-- | src/slskd/Core/API/Controllers/ApplicationController.cs | 33 |
1 files changed, 26 insertions, 7 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); |
