From 058b02ea093f4d7867441d055bef2b857eb98dd0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 31 May 2026 14:54:01 -0500 Subject: always split by both slashes --- src/slskd/Common/FileSafety.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/slskd/Common/FileSafety.cs b/src/slskd/Common/FileSafety.cs index 479f7834..ebd9a69c 100644 --- a/src/slskd/Common/FileSafety.cs +++ b/src/slskd/Common/FileSafety.cs @@ -130,7 +130,7 @@ public static class FileSafety } } - var parts = segment.Split(Path.DirectorySeparatorChar, '\\', '/'); + var parts = segment.Split('\\', '/'); // ensure the segments we're combining don't contain traversal segments "." or ".." // untrusted input could use this to "break out" of the root directory and access sensitive areas @@ -234,8 +234,7 @@ public static class FileSafety return null; } - return LocalizePath(path, os) - .Split(Path.DirectorySeparatorChar) + var segments = localPath.Split('/', '\\'); .TakeLast(1) .Select(s => sanitize == true ? SanitizePathSegment(s, os: os) : s) .Single(); @@ -258,7 +257,7 @@ public static class FileSafety var local = LocalizePath(path, os: os); return string.Join(Path.DirectorySeparatorChar, local - .Split(Path.DirectorySeparatorChar) + .Split('/', '\\') .SkipLast(1) .Select(s => sanitize == true ? SanitizePathSegment(s, os: os) : s)); } @@ -379,7 +378,7 @@ public static class FileSafety // for each segment, drop nulls (created by double slashes), sanitize, and replace traversal strings var segments = path - .Split(sep) + .Split('/', '\\') .Select(s => SanitizeFilename(s, replacement, os)) .Select(s => s is "." or ".." ? replacement.ToString() : s); -- cgit v1.2.3