aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Validation/AbsolutePathAttribute.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/slskd/Common/Validation/AbsolutePathAttribute.cs')
-rw-r--r--src/slskd/Common/Validation/AbsolutePathAttribute.cs11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/slskd/Common/Validation/AbsolutePathAttribute.cs b/src/slskd/Common/Validation/AbsolutePathAttribute.cs
index 0eeb4a38..4c9f5e53 100644
--- a/src/slskd/Common/Validation/AbsolutePathAttribute.cs
+++ b/src/slskd/Common/Validation/AbsolutePathAttribute.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 absolute.
@@ -47,14 +45,13 @@ namespace slskd.Validation
{
var path = value.ToString();
- if (!Path.IsPathRooted(path))
+ if (!FileSafety.IsPathAbsolute(path))
{
- return new ValidationResult($"The {validationContext.DisplayName} field must specify an absolute file path.");
+ return new ValidationResult($"The {validationContext.DisplayName} field must be an absolute file 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 '..')");
}