]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: Allow read-only filename validation to allow reading files
authorFerdinand Thiessen <opensource@fthiessen.de>
Tue, 27 Aug 2024 12:06:23 +0000 (14:06 +0200)
committerFerdinand Thiessen <opensource@fthiessen.de>
Wed, 28 Aug 2024 18:23:54 +0000 (20:23 +0200)
Needed to read files with the "Windows compatibility" feature.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
apps/dav/lib/Connector/Sabre/Directory.php
lib/private/Files/View.php

index 427ec59bc31602052114d14d9e298117efe4c86c..d56f56890cc7ff0594d217abc251a5c8c9bc307a 100644 (file)
@@ -173,7 +173,7 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node implements \Sabre\DAV\ICol
                $path = $this->path . '/' . $name;
                if (is_null($info)) {
                        try {
-                               $this->fileView->verifyPath($this->path, $name);
+                               $this->fileView->verifyPath($this->path, $name, true);
                                $info = $this->fileView->getFileInfo($path);
                        } catch (\OCP\Files\StorageNotAvailableException $e) {
                                throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage(), 0, $e);
index 0e5e433ccb689530b37f70b556aa392fc2373ff3..d8b240d5b11ce8dadc4a4a840a59fee082f6bbac 100644 (file)
@@ -1826,15 +1826,26 @@ class View {
        /**
         * @param string $path
         * @param string $fileName
+        * @param bool $readonly Check only if the path is allowed for read-only access
         * @throws InvalidPathException
         */
-       public function verifyPath($path, $fileName): void {
+       public function verifyPath($path, $fileName, $readonly = false): void {
                // All of the view's functions disallow '..' in the path so we can short cut if the path is invalid
                if (!Filesystem::isValidPath($path ?: '/')) {
                        $l = \OCP\Util::getL10N('lib');
                        throw new InvalidPathException($l->t('Path contains invalid segments'));
                }
 
+               // Short cut for read-only validation
+               if ($readonly) {
+                       $validator = \OCP\Server::get(FilenameValidator::class);
+                       if ($validator->isForbidden($fileName)) {
+                               $l = \OCP\Util::getL10N('lib');
+                               throw new InvalidPathException($l->t('Filename is a reserved word'));
+                       }
+                       return;
+               }
+
                try {
                        /** @type \OCP\Files\Storage $storage */
                        [$storage, $internalPath] = $this->resolvePath($path);