diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-05-14 09:30:35 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-05-14 09:30:35 -0500 |
| commit | e6cc409dbe1818b3cd60b2fe7241428684e2665f (patch) | |
| tree | 035d38c432787f33d1e4d0037e200b8ccb41cefa /src | |
| parent | 016246421704db4311dcdfb8e611c7ca6a2198a3 (diff) | |
| download | slskd-e6cc409dbe1818b3cd60b2fe7241428684e2665f.tar.gz | |
prevent path traversal attacks from enqueue or directory content requests
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index e36a5539..e3d212f7 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -572,6 +572,14 @@ namespace slskd { Metrics.Enqueue.RequestsReceived.Inc(1); + // it shouldn't be possible for us to be sharing any such files, as share paths are required to be absolute and rooted + // if someone is requesting a file like this, something is either really wrong, or they are a bad actor + if (FileSafety.ContainsTraversalSegments(filename)) + { + Log.Warning("Suspicious attempt from user {Username} to enqueue a file containing unsafe path segments (one or more of path traversal characters '.' and '..'). Requested file: {File}", username, filename); + throw new DownloadEnqueueException("File not shared."); + } + /* circuit breaker/failsafe: @@ -1413,6 +1421,14 @@ 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) { + // we shouldn't be sharing any files with these segments because shares are required to be absolute and rooted + // if we see this, something has either gone really wrong, or someone is trying something funny + if (FileSafety.ContainsTraversalSegments(directory)) + { + Log.Warning("Suspicious attempt from user {Username} to list a directory containing unsafe path segments (one or more of path traversal characters '.' and '..'). Requested file: {File}", username, directory); + return []; + } + if (Users.IsBlacklisted(username, endpoint.Address)) { Log.Information("Returned empty directory listing for blacklisted user {Username} ({IP})", username, endpoint.Address); |
