aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-17 13:40:48 -0500
committerJP Dillingham <jp@dillingham.me>2026-05-17 13:40:48 -0500
commit946333991d4f06aa139e9659952b2ce2ca9e988d (patch)
tree9f77ce336372a3e96bad8a1b7cbb6604b088a992 /src
parent5d16f6f9cccf72c29b8bbf206c851005e3375d79 (diff)
downloadslskd-946333991d4f06aa139e9659952b2ce2ca9e988d.tar.gz
mess with tests and validation
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Validation/AbsolutePathAttribute.cs6
-rw-r--r--src/slskd/Common/Validation/GuidAttribute.cs26
-rw-r--r--src/slskd/Common/Validation/RelativePathAttribute.cs6
-rw-r--r--src/slskd/Core/Options.cs3
-rw-r--r--src/slskd/Transfers/API/Controllers/TransfersController.cs4
-rw-r--r--src/slskd/Transfers/API/DTO/QueueDownloadBatchRequest.cs3
6 files changed, 31 insertions, 17 deletions
diff --git a/src/slskd/Common/Validation/AbsolutePathAttribute.cs b/src/slskd/Common/Validation/AbsolutePathAttribute.cs
index 4c9f5e53..1999220f 100644
--- a/src/slskd/Common/Validation/AbsolutePathAttribute.cs
+++ b/src/slskd/Common/Validation/AbsolutePathAttribute.cs
@@ -49,12 +49,6 @@ namespace slskd.Validation
{
return new ValidationResult($"The {validationContext.DisplayName} field must be an absolute file path.");
}
-
- // unrelated to absolute/relative check; we disallow traversal segments across the board so check while we're here
- if (FileSafety.ContainsTraversalSegments(path))
- {
- return new ValidationResult($"The {validationContext.DisplayName} field contains one or more unsafe path traversal segments ('.' or '..')");
- }
}
return ValidationResult.Success;
diff --git a/src/slskd/Common/Validation/GuidAttribute.cs b/src/slskd/Common/Validation/GuidAttribute.cs
index 5728b8f6..f61527a4 100644
--- a/src/slskd/Common/Validation/GuidAttribute.cs
+++ b/src/slskd/Common/Validation/GuidAttribute.cs
@@ -32,6 +32,8 @@
namespace slskd.Validation
{
+ using System;
+
using System.ComponentModel.DataAnnotations;
/// <summary>
@@ -39,6 +41,13 @@ namespace slskd.Validation
/// </summary>
public class GuidAttribute : ValidationAttribute
{
+ public GuidAttribute(bool allowEmpty = false)
+ {
+ AllowEmpty = allowEmpty;
+ }
+
+ public bool AllowEmpty { get; }
+
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value is null)
@@ -46,8 +55,23 @@ namespace slskd.Validation
return ValidationResult.Success;
}
- if (value is string str && System.Guid.TryParse(str, out _))
+ if (value is Guid guid)
{
+ if (!AllowEmpty && guid == Guid.Empty)
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field must not contain an empty GUID/UUID");
+ }
+
+ return ValidationResult.Success;
+ }
+
+ if (value is string str && Guid.TryParse(str, out guid))
+ {
+ if (!AllowEmpty && guid == Guid.Empty)
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field must not contain an empty GUID/UUID");
+ }
+
return ValidationResult.Success;
}
diff --git a/src/slskd/Common/Validation/RelativePathAttribute.cs b/src/slskd/Common/Validation/RelativePathAttribute.cs
index e8865554..64e418b1 100644
--- a/src/slskd/Common/Validation/RelativePathAttribute.cs
+++ b/src/slskd/Common/Validation/RelativePathAttribute.cs
@@ -49,12 +49,6 @@ namespace slskd.Validation
{
return new ValidationResult($"The {validationContext.DisplayName} field must be a relative path.");
}
-
- // unrelated to absolute/relative check; we disallow traversal segments across the board so check while we're here
- if (FileSafety.ContainsTraversalSegments(path))
- {
- return new ValidationResult($"The {validationContext.DisplayName} field contains one or more unsafe path traversal segments ('.' or '..')");
- }
}
return ValidationResult.Success;
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 21f2c75f..3d9c8fb2 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -766,6 +766,7 @@ namespace slskd
[EnvironmentVariable("INCOMPLETE_DIR")]
[Description("path where incomplete downloads are saved")]
[AbsolutePath]
+ [NonTraversingPath]
[DirectoryExists(ensureWriteable: true)]
[RequiresRestart]
public string Incomplete { get; init; } = Program.DefaultIncompleteDirectory;
@@ -777,6 +778,7 @@ namespace slskd
[EnvironmentVariable("DOWNLOADS_DIR")]
[Description("path where downloaded files are saved")]
[AbsolutePath]
+ [NonTraversingPath]
[DirectoryExists(ensureWriteable: true)]
[RequiresRestart]
public string Downloads { get; init; } = Program.DefaultDownloadsDirectory;
@@ -2013,6 +2015,7 @@ namespace slskd
[EnvironmentVariable("HTTP_SOCKET")]
[Description("HTTP listen unix domain socket (UDS) path for web UI")]
[AbsolutePath]
+ [NonTraversingPath]
[RequiresRestart]
public string Socket { get; init; }
diff --git a/src/slskd/Transfers/API/Controllers/TransfersController.cs b/src/slskd/Transfers/API/Controllers/TransfersController.cs
index 01dd61bd..3191e3a8 100644
--- a/src/slskd/Transfers/API/Controllers/TransfersController.cs
+++ b/src/slskd/Transfers/API/Controllers/TransfersController.cs
@@ -385,7 +385,7 @@ namespace slskd.Transfers.API
if (failed.Count > 0)
{
- Log.Warning("Failed to enqueue {Count} of {Total} files for {Username}; transfers already queued, in progress, or an error occurred (batch Id: {BatchId}). Failues: {Failures}", failed.Count, request.Files.Count, batchId, failed);
+ Log.Warning("Failed to enqueue {Count} of {Total} files from {Username}; transfers already queued, in progress, or an error occurred (batch Id: {BatchId}). Failues: {Failures}", failed.Count, request.Files.Count, request.Username, batchId, failed);
}
// the returned batch will have whatever Transfers were successfully inserted attached (via Include())
@@ -488,7 +488,7 @@ namespace slskd.Transfers.API
if (!Guid.TryParse(id, out var guid))
{
- return BadRequest();
+ return BadRequest($"The specified id {id} is not a valid GUID/UUID");
}
try
diff --git a/src/slskd/Transfers/API/DTO/QueueDownloadBatchRequest.cs b/src/slskd/Transfers/API/DTO/QueueDownloadBatchRequest.cs
index 53f5290f..c1b7d725 100644
--- a/src/slskd/Transfers/API/DTO/QueueDownloadBatchRequest.cs
+++ b/src/slskd/Transfers/API/DTO/QueueDownloadBatchRequest.cs
@@ -61,8 +61,7 @@ public record QueueDownloadBatchRequest
/// The username of the user from which to download.
/// </summary>
[Required]
- [NotNullOrWhiteSpace]
- [StringLength(maximumLength: 500)]
+ [String(AllowNull = false, AllowEmpty = false, AllowWhiteSpace = false, MinimumLength = 1, MaximumLength = 500)]
public string Username { get; init; }
/// <summary>