]> source.dussan.org Git - nextcloud-server.git/commitdiff
Prevent directory traversals in ctr of \OC\Files\View
authorLukas Reschke <lukas@owncloud.com>
Wed, 18 Feb 2015 15:01:24 +0000 (16:01 +0100)
committerLukas Reschke <lukas@owncloud.com>
Wed, 18 Feb 2015 17:17:33 +0000 (18:17 +0100)
This prevents a misusage of \OC\Files\View by calling it with user-supplied input. In such cases an exception is now thrown.

lib/private/files/view.php
tests/lib/files/view.php

index 3bc9fdff1ee6ad53679aa0472efb42099ff0d930..3dfd4d0c105da92ec29667c156a0f803f5fe2814 100644 (file)
@@ -36,7 +36,15 @@ class View {
         */
        protected $updater;
 
+       /**
+        * @param string $root
+        * @throws \Exception If $root contains an invalid path
+        */
        public function __construct($root = '') {
+               if(!Filesystem::isValidPath($root)) {
+                       throw new \Exception();
+               }
+
                $this->fakeRoot = $root;
                $this->updater = new Updater($this);
        }
index f6af59d52be57f1251156b3c80914f947714f5da..b4b6d0deb2ea69be34782db07505f88bce8d3a3e 100644 (file)
@@ -894,4 +894,21 @@ class View extends \Test\TestCase {
                $this->assertFalse($view->unlink('foo.txt'));
                $this->assertTrue($cache->inCache('foo.txt'));
        }
+
+       function directoryTraversalProvider() {
+               return [
+                       ['../test/'],
+                       ['..\\test\\my/../folder'],
+                       ['/test/my/../foo\\'],
+               ];
+       }
+
+       /**
+        * @dataProvider directoryTraversalProvider
+        * @expectedException \Exception
+        * @param string $root
+        */
+       public function testConstructDirectoryTraversalException($root) {
+               new \OC\Files\View($root);
+       }
 }