From 4d35aa93d565b931ae06188beb2aca242619cb7f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 9 May 2026 19:03:59 -0500 Subject: guard against path traversal in enqueue/directory requests --- src/slskd/Application.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') 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 /// A Task resolving an instance of Soulseek.Directory containing the contents of the requested directory. private async Task> 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); -- cgit v1.2.3