aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-09 19:03:59 -0500
committerJP Dillingham <jp@dillingham.me>2026-05-09 19:03:59 -0500
commit4d35aa93d565b931ae06188beb2aca242619cb7f (patch)
treea50edf325291b995dc994e5ae44266887d6b388f /src
parent9f68821f91a643c872a7023d6abf2c2f7cb60474 (diff)
downloadslskd-4d35aa93d565b931ae06188beb2aca242619cb7f.tar.gz
guard against path traversal in enqueue/directory requests
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application.cs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index e36a5539..c69df4c9 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -572,6 +572,12 @@ namespace slskd
{
Metrics.Enqueue.RequestsReceived.Inc(1);
+ if (filename.Split('\\', '/').Any(s => s == ".." || s == "."))
+ {
+ Log.Warning("Suspicious attempt from user {Username} to enqueue a file containing unsafe or malformed path segments (one or more of: empty segments, path traversal characters '.' and '..'). Requested file: {File}", username, filename);
+ throw new DownloadEnqueueException("File not shared.");
+ }
+
/*
circuit breaker/failsafe:
@@ -1413,6 +1419,12 @@ namespace slskd
/// <returns>A Task resolving an instance of Soulseek.Directory containing the contents of the requested directory.</returns>
private async Task<IEnumerable<Soulseek.Directory>> DirectoryContentsResponseResolver(string username, IPEndPoint endpoint, int token, string directory)
{
+ if (directory.Split('\\', '/').Any(s => s == ".." || s == "."))
+ {
+ Log.Warning("Suspicious attempt from user {Username} to list the contents of a directory containing unsafe or malformed path segments (one or more of: empty segments, path traversal characters '.' and '..'). Requested directory: {Directory}", username, directory);
+ throw new DownloadEnqueueException("File not shared.");
+ }
+
if (Users.IsBlacklisted(username, endpoint.Address))
{
Log.Information("Returned empty directory listing for blacklisted user {Username} ({IP})", username, endpoint.Address);