aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Files
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-14 09:22:27 -0500
committerJP Dillingham <jp@dillingham.me>2026-05-14 09:22:27 -0500
commit95d0bf9a6558fdb32066e1d028795c4693dedf02 (patch)
tree8aacc11c6f901c18322efea50abe00f7ea960f60 /src/slskd/Files
parent4f40140e9debd0976b0cabf47a1f2ec02598e3ea (diff)
downloadslskd-95d0bf9a6558fdb32066e1d028795c4693dedf02.tar.gz
strengthen check of allowed paths
Diffstat (limited to 'src/slskd/Files')
-rw-r--r--src/slskd/Files/FileService.cs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/slskd/Files/FileService.cs b/src/slskd/Files/FileService.cs
index 575619d5..4b281863 100644
--- a/src/slskd/Files/FileService.cs
+++ b/src/slskd/Files/FileService.cs
@@ -164,7 +164,7 @@ namespace slskd.Files
}
// important! we must fully expand the given paths with GetFullPath() to resolve a given relative directory, like '..'
- bool IsAllowed(string path) => AllowedDirectories.Any(allowed => path.StartsWith(allowed));
+ bool IsAllowed(string path) => AllowedDirectories.Any(allowed => path.StartsWith(allowed + Path.DirectorySeparatorChar) || path == allowed);
// if any of the resolved directory paths aren't rooted in one of the allowed directories, forbid the entire request
if (!directories.All(directory => IsAllowed(directory)))
@@ -222,7 +222,7 @@ namespace slskd.Files
}
// important! we must fully expand the given paths with GetFullPath() to resolve a given relative directory, like '..'
- bool IsAllowed(string path) => AllowedDirectories.Any(allowed => path.StartsWith(allowed));
+ bool IsAllowed(string path) => AllowedDirectories.Any(allowed => path.StartsWith(allowed + Path.DirectorySeparatorChar) || path == allowed);
// if any of the resolved file paths aren't rooted in one of the allowed directories, forbid the entire request
if (!files.All(file => IsAllowed(file)))