diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-05-13 18:15:16 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-05-13 18:38:34 -0500 |
| commit | 8336a3c3ebdfc65dd7d7419f27c195a4aa729856 (patch) | |
| tree | 253c6dd1b62b8276d3fa880c92bd1c24db3c7a6e /src/slskd/Common/Validation/RelativePathAttribute.cs | |
| parent | fe1a6a3298116bc3980306cbb287f7137b378d1a (diff) | |
| download | slskd-8336a3c3ebdfc65dd7d7419f27c195a4aa729856.tar.gz | |
write our own logic for path relative/absolute
Diffstat (limited to 'src/slskd/Common/Validation/RelativePathAttribute.cs')
| -rw-r--r-- | src/slskd/Common/Validation/RelativePathAttribute.cs | 9 |
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 '..')"); } |
