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.cs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/slskd/Common/Validation/AbsolutePathAttribute.cs b/src/slskd/Common/Validation/AbsolutePathAttribute.cs
index ef6db8ca..9f6184ce 100644
--- a/src/slskd/Common/Validation/AbsolutePathAttribute.cs
+++ b/src/slskd/Common/Validation/AbsolutePathAttribute.cs
@@ -34,6 +34,7 @@ namespace slskd.Validation
{
using System.ComponentModel.DataAnnotations;
using System.IO;
+ using System.Linq;
/// <summary>
/// Validates that the specified path is absolute.
@@ -44,9 +45,21 @@ namespace slskd.Validation
{
if (value != null)
{
- var filePath = value.ToString();
+ var path = value.ToString();
- if (!string.IsNullOrEmpty(filePath) && !Path.IsPathRooted(filePath))
+ var segments = path.Split('/', '\\');
+
+ if (segments.Any(s => string.IsNullOrEmpty(s)))
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field contains one or more empty segments ('\\\\' or '//')");
+ }
+
+ if (segments.Any(s => s == ".." || s == "."))
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field contains one or more unsafe path traversal segments ('.' or '..')");
+ }
+
+ if (!string.IsNullOrEmpty(path) && !Path.IsPathRooted(path))
{
return new ValidationResult($"The {validationContext.DisplayName} field must specify an absolute file path.");
}