aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/API/Controllers/ApplicationController.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-10-22 21:54:18 -0500
committerJP Dillingham <jp@dillingham.me>2026-10-22 21:54:18 -0500
commit46c4714a1377d698f6b35879a276d8be8f11dfe7 (patch)
tree78725e152df0a15226ba607961a9d647b773fcdc /src/slskd/Core/API/Controllers/ApplicationController.cs
parentc9b85e9f1280a4efa70c0401fdf3677eadefec4e (diff)
downloadslskd-46c4714a1377d698f6b35879a276d8be8f11dfe7.tar.gz
require administrator role for dumps, check Dumpable option first
Diffstat (limited to 'src/slskd/Core/API/Controllers/ApplicationController.cs')
-rw-r--r--src/slskd/Core/API/Controllers/ApplicationController.cs22
1 files changed, 18 insertions, 4 deletions
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;
/// <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>();
@@ -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<IActionResult> 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)]