aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-11 19:04:44 -0500
committerJP Dillingham <jp@dillingham.me>2026-05-11 19:04:44 -0500
commit4b0b663a5bc1dc64d52485eb7be1bce5df73478c (patch)
treeed17cfa16fe7c4c0ca5e44b1a0979edcdccacf9b /src
parent7cd70a730b6cd57952f2e233378cd6bb244f56b1 (diff)
downloadslskd-4b0b663a5bc1dc64d52485eb7be1bce5df73478c.tar.gz
wip
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Relay/API/Controllers/RelayController.cs7
-rw-r--r--src/slskd/Relay/RelayClient.cs25
2 files changed, 29 insertions, 3 deletions
diff --git a/src/slskd/Relay/API/Controllers/RelayController.cs b/src/slskd/Relay/API/Controllers/RelayController.cs
index 0d2ef9c5..f0ab0457 100644
--- a/src/slskd/Relay/API/Controllers/RelayController.cs
+++ b/src/slskd/Relay/API/Controllers/RelayController.cs
@@ -159,7 +159,12 @@ namespace slskd.Relay
return Unauthorized();
}
- var sourceFile = Path.Combine(OptionsMonitor.CurrentValue.Directories.Downloads, filename);
+ // if we get this far, the caller has supplied a valid credential and filename, meaning the request
+ // to download is being made in response to the controller signaling the agent that a download had completed.
+ // it's not possible for the client to download arbitrary files; credentials are computed from a token, and
+ // this token is cached in the controller, so only file downloads that the controller solicited are possible
+ // still, for the abundance of caution, use the CombineSafely method in case the filename has traversal segments
+ var sourceFile = FileSafety.CombineSafely(OptionsMonitor.CurrentValue.Directories.Downloads, filename);
Log.Information("Agent {Agent} authenticated for token {Token}. Sending file {Filename}", agentName, guid, filename);
diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs
index 9aec7b00..6d4b872a 100644
--- a/src/slskd/Relay/RelayClient.cs
+++ b/src/slskd/Relay/RelayClient.cs
@@ -370,6 +370,13 @@ namespace slskd.Relay
private async Task HandleFileInfoRequest(string filename, Guid id)
{
+ if (FileSafety.ContainsTraversalSegments(filename))
+ {
+ var msg = $"Suspicious attempt to request file info containing unsafe path segments (one or more of path traversal characters '.' and '..'). Requested file: {filename}";
+ Log.Warning(msg, filename);
+ throw new ArgumentException(msg, nameof(filename));
+ }
+
Log.Information("Relay controller requested file info for {Filename} with ID {Id}", filename, id);
try
@@ -389,6 +396,13 @@ namespace slskd.Relay
private Task HandleFileUploadRequest(string filename, long startOffset, Guid token)
{
+ if (FileSafety.ContainsTraversalSegments(filename))
+ {
+ var msg = $"Suspicious attempt to request a file upload containing unsafe path segments (one or more of path traversal characters '.' and '..'). Requested file: {filename}";
+ Log.Warning(msg, filename);
+ throw new ArgumentException(msg, nameof(filename));
+ }
+
_ = Task.Run(async () =>
{
Log.Information("Relay controller requested file {Filename} with ID {Id}", filename, token);
@@ -448,6 +462,13 @@ namespace slskd.Relay
private Task HandleNotifyFileDownloadCompleted(string filename, Guid token)
{
+ if (FileSafety.ContainsTraversalSegments(filename))
+ {
+ var msg = $"Suspicious attempt to solicit a file download containing unsafe path segments (one or more of path traversal characters '.' and '..'). Requested file: {filename}";
+ Log.Warning(msg, filename);
+ throw new ArgumentException(msg, nameof(filename));
+ }
+
if (!OptionsMonitor.CurrentValue.Relay.Controller.Downloads)
{
return Task.CompletedTask;
@@ -457,13 +478,13 @@ namespace slskd.Relay
_ = Task.Run(async () =>
{
- var destinationFile = Path.Combine(OptionsMonitor.CurrentValue.Directories.Downloads, filename);
+ var destinationFile = FileSafety.CombineSafely(OptionsMonitor.CurrentValue.Directories.Downloads, filename);
if (OptionsMonitor.CurrentValue.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Debug)
{
// if we're debugging, we're referencing the same file for both the controller and agent which will lead to an
// access violation. prefix the destination file to avoid this.
- destinationFile = Path.Combine(OptionsMonitor.CurrentValue.Directories.Downloads, $"{filename}.relayed");
+ destinationFile = FileSafety.CombineSafely(OptionsMonitor.CurrentValue.Directories.Downloads, $"{filename}.relayed");
}
// if the controller is Windows and the agent is Linux or vice versa, we need to translate the filename to the