aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Validation/RelativePathAttribute.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/slskd/Common/Validation/RelativePathAttribute.cs')
-rw-r--r--src/slskd/Common/Validation/RelativePathAttribute.cs9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/slskd/Common/Validation/RelativePathAttribute.cs b/src/slskd/Common/Validation/RelativePathAttribute.cs
index 824ff18d..e8865554 100644
--- a/src/slskd/Common/Validation/RelativePathAttribute.cs
+++ b/src/slskd/Common/Validation/RelativePathAttribute.cs
@@ -33,8 +33,6 @@
namespace slskd.Validation
{
using System.ComponentModel.DataAnnotations;
- using System.IO;
- using System.Linq;
/// <summary>
/// Validates that the specified path is relative.
@@ -47,14 +45,13 @@ namespace slskd.Validation
{
var path = value.ToString();
- if (Path.IsPathRooted(path))
+ if (!FileSafety.IsPathRelative(path))
{
return new ValidationResult($"The {validationContext.DisplayName} field must be a relative path.");
}
- var segments = path.Split('/', '\\');
-
- if (segments.Any(s => s == ".." || s == "."))
+ // 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 '..')");
}