aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-10-22 22:39:13 -0500
committerGitHub <noreply@github.com>2026-10-22 22:39:13 -0500
commit6be4f40d3079089ec91d48b05400a1b92b8ca899 (patch)
treeb022b5290a792a6bfea928315f06c359e86e8b5a
parent4b84358f9ee5074873b4f0cc1030c97b10154e46 (diff)
parent757c21eb1eb9c88ad46b789561f5dc5a6c7488eb (diff)
downloadslskd-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
-rw-r--r--src/slskd/Common/Authentication/AuthRole.cs9
-rw-r--r--src/slskd/Common/Authentication/Role.cs1
-rw-r--r--src/slskd/Core/API/Controllers/ApplicationController.cs33
-rw-r--r--src/slskd/Core/API/Controllers/DebugController.cs3
-rw-r--r--src/slskd/Core/API/Controllers/LogsController.cs1
-rw-r--r--src/slskd/Core/API/Controllers/OptionsController.cs7
-rw-r--r--src/slskd/Core/API/Controllers/ServerController.cs5
-rw-r--r--src/slskd/Core/Options.cs13
-rw-r--r--src/slskd/Program.cs5
9 files changed, 59 insertions, 18 deletions
diff --git a/src/slskd/Common/Authentication/AuthRole.cs b/src/slskd/Common/Authentication/AuthRole.cs
index 958cc143..e9cd38aa 100644
--- a/src/slskd/Common/Authentication/AuthRole.cs
+++ b/src/slskd/Common/Authentication/AuthRole.cs
@@ -32,6 +32,8 @@
namespace slskd
{
+ using slskd.Authentication;
+
/// <summary>
/// Authentication roles.
/// </summary>
@@ -40,9 +42,8 @@ namespace slskd
/// </remarks>
public static class AuthRole
{
- public const string AdministratorOnly = "Administrator";
- public const string ReadWriteOrAdministrator = "ReadWrite,Administrator";
- public const string GuestOrAdministrator = "Guest,Administrator";
- public const string Any = "ReadOnly,ReadWrite,Guest,Administrator";
+ public const string AdministratorOnly = $"{nameof(Role.Administrator)}";
+ public const string ReadWriteOrAdministrator = $"{nameof(Role.ReadWrite)},{nameof(Role.Administrator)}";
+ public const string Any = $"{nameof(Role.ReadOnly)},{nameof(Role.ReadWrite)},{nameof(Role.Administrator)}";
}
}
diff --git a/src/slskd/Common/Authentication/Role.cs b/src/slskd/Common/Authentication/Role.cs
index d081c198..42314c2d 100644
--- a/src/slskd/Common/Authentication/Role.cs
+++ b/src/slskd/Common/Authentication/Role.cs
@@ -36,7 +36,6 @@ namespace slskd.Authentication
{
ReadOnly = 0,
ReadWrite = 1,
- Guest = 2,
Administrator = 3,
}
}
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)
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 05eaed57..d2aba37f 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -484,6 +484,19 @@ namespace slskd
public bool Volatile { get; init; } = false;
/// <summary>
+ /// Gets a value indicating whether real-time memory dumping via API is enabled.
+ /// </summary>
+ /// <remarks>
+ /// This can expose sensitive information, and should be turned on only to diagnose memory leaks.
+ /// As such, it is and must remain undocumented.
+ /// </remarks>
+ [Argument(default, "dumpable")]
+ [EnvironmentVariable("DUMPABLE")]
+ [Description("enable run-time memory dumps via api")]
+ [RequiresRestart]
+ public bool Dumpable { get; init; } = false;
+
+ /// <summary>
/// Gets a value indicating whether user-defined regular expressions are case sensitive.
/// </summary>
[Argument(default, "case-sensitive-regex")]
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index e236886b..cdfbbf33 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -509,6 +509,11 @@ namespace slskd
Log.Information("Using application directory {AppDirectory}", AppDirectory);
Log.Information("Using configuration file {ConfigurationFile}", ConfigurationFile);
+ if (OptionsAtStartup.Flags.Dumpable)
+ {
+ Log.Warning("Application memory dumps are ENABLED; this can expose sensitive information, including environment variables from the shell. Disable Flags.Dumpable to disable.");
+ }
+
if (OptionsAtStartup.Flags.NoConfigWatch)
{
Log.Warning("Configuration watch DISABLED; all configuration changes will require a restart to take effect");