aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Validation/AbsolutePathAttribute.cs15
-rw-r--r--src/slskd/Common/Validation/RelativePathAttribute.cs15
2 files changed, 10 insertions, 20 deletions
diff --git a/src/slskd/Common/Validation/AbsolutePathAttribute.cs b/src/slskd/Common/Validation/AbsolutePathAttribute.cs
index 9f6184ce..0eeb4a38 100644
--- a/src/slskd/Common/Validation/AbsolutePathAttribute.cs
+++ b/src/slskd/Common/Validation/AbsolutePathAttribute.cs
@@ -43,26 +43,21 @@ namespace slskd.Validation
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
- if (value != null)
+ if (value != null && value is string str && !string.IsNullOrEmpty(str))
{
var path = value.ToString();
- var segments = path.Split('/', '\\');
-
- if (segments.Any(s => string.IsNullOrEmpty(s)))
+ if (!Path.IsPathRooted(path))
{
- return new ValidationResult($"The {validationContext.DisplayName} field contains one or more empty segments ('\\\\' or '//')");
+ return new ValidationResult($"The {validationContext.DisplayName} field must specify an absolute file path.");
}
+ var segments = path.Split('/', '\\');
+
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.");
- }
}
return ValidationResult.Success;
diff --git a/src/slskd/Common/Validation/RelativePathAttribute.cs b/src/slskd/Common/Validation/RelativePathAttribute.cs
index 3bd48766..824ff18d 100644
--- a/src/slskd/Common/Validation/RelativePathAttribute.cs
+++ b/src/slskd/Common/Validation/RelativePathAttribute.cs
@@ -43,26 +43,21 @@ namespace slskd.Validation
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
- if (value != null)
+ if (value != null && value is string str && !string.IsNullOrEmpty(str))
{
var path = value.ToString();
- var segments = path.Split('/', '\\');
-
- if (segments.Any(s => string.IsNullOrEmpty(s)))
+ if (Path.IsPathRooted(path))
{
- return new ValidationResult($"The {validationContext.DisplayName} field contains one or more empty segments ('\\\\' or '//')");
+ return new ValidationResult($"The {validationContext.DisplayName} field must be a relative path.");
}
+ var segments = path.Split('/', '\\');
+
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 be a relative path.");
- }
}
return ValidationResult.Success;