diff --git a/lib/Controller/PublicController.php b/lib/Controller/PublicController.php index f0b022ab..77b240e8 100644 --- a/lib/Controller/PublicController.php +++ b/lib/Controller/PublicController.php @@ -196,9 +196,10 @@ class PublicController extends AuthPublicShareController $relPath = substr($node->getPath(), \strlen($userFolder->getPath())); // Get the user's folders path - $foldersPath = $this->config->getUserValue($user->getUID(), Application::APPNAME, 'foldersPath', ''); - $foldersPath = $foldersPath ?: '/'; - $foldersPath = Util::sanitizePath($foldersPath); + $foldersPath = $this->config->getUserValue($user->getUID(), Application::APPNAME, 'foldersPath', null) ?: '/'; + + // Sanitize folders path ensuring leading and trailing slashes + $foldersPath = Util::sanitizePath('/' . $foldersPath . '/'); // Check if relPath starts with foldersPath if (0 !== strpos($relPath, $foldersPath)) { diff --git a/lib/Util.php b/lib/Util.php index e06e56c4..f4318287 100644 --- a/lib/Util.php +++ b/lib/Util.php @@ -324,7 +324,7 @@ class Util /** * Sanitize a path to keep only ASCII characters and special characters. */ - public static function sanitizePath(string $path) + public static function sanitizePath(string $path): string { $path = str_replace("\0", '', $path); // remove null characters