aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common
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/slskd/Common
parent5d16f6f9cccf72c29b8bbf206c851005e3375d79 (diff)
downloadslskd-946333991d4f06aa139e9659952b2ce2ca9e988d.tar.gz
mess with tests and validation
Diffstat (limited to 'src/slskd/Common')
-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
3 files changed, 25 insertions, 13 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;