diff options
author | Git'Fellow <12234510+solracsf@users.noreply.github.com> | 2024-09-04 22:24:19 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2024-09-06 01:59:29 +0000 |
commit | 01596b54c039a7f1b57fe4198f9c18a73aa8a6da (patch) | |
tree | 3d959a404ba8b881e4e32bd1870423e1cae2d593 | |
parent | 7ec40bfe3585c2b1a7f6b08fd7a2358c1c41cd0b (diff) | |
download | nextcloud-server-01596b54c039a7f1b57fe4198f9c18a73aa8a6da.tar.gz nextcloud-server-01596b54c039a7f1b57fe4198f9c18a73aa8a6da.zip |
fix(files): Check if the target path is a descendant of the shared folder pathbackport/47756/stable29
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
fix: tests
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
fix: fix tests
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
fix: add tests
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
fix: tests
-rw-r--r-- | lib/private/Files/View.php | 3 | ||||
-rw-r--r-- | tests/lib/Files/ViewTest.php | 10 |
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index efe3bcf5abc..b6b136ab178 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1829,7 +1829,8 @@ class View { }, $providers)); foreach ($shares as $share) { - if (str_starts_with($targetPath, $share->getNode()->getPath())) { + $sharedPath = $share->getNode()->getPath(); + if ($targetPath === $sharedPath || str_starts_with($targetPath, $sharedPath . '/')) { $this->logger->debug( 'It is not allowed to move one mount point into a shared folder', ['app' => 'files']); diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index 16568e74a06..8396857e80f 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -1668,17 +1668,24 @@ class ViewTest extends \Test\TestCase { public function testMoveMountPointIntoSharedFolder() { self::loginAsUser($this->user); - [$mount1] = $this->createTestMovableMountPoints([ + [$mount1, $mount2] = $this->createTestMovableMountPoints([ $this->user . '/files/mount1', + $this->user . '/files/mount2', ]); $mount1->expects($this->never()) ->method('moveMount'); + $mount2->expects($this->once()) + ->method('moveMount') + ->willReturn(true); + $view = new View('/' . $this->user . '/files/'); $view->mkdir('shareddir'); $view->mkdir('shareddir/sub'); $view->mkdir('shareddir/sub2'); + // Create a similar named but non-shared folder + $view->mkdir('shareddir notshared'); $fileId = $view->getFileInfo('shareddir')->getId(); $userObject = \OC::$server->getUserManager()->createUser('test2', 'IHateNonMockableStaticClasses'); @@ -1697,6 +1704,7 @@ class ViewTest extends \Test\TestCase { $this->assertFalse($view->rename('mount1', 'shareddir'), 'Cannot overwrite shared folder'); $this->assertFalse($view->rename('mount1', 'shareddir/sub'), 'Cannot move mount point into shared folder'); $this->assertFalse($view->rename('mount1', 'shareddir/sub/sub2'), 'Cannot move mount point into shared subfolder'); + $this->assertTrue($view->rename('mount2', 'shareddir notshared/sub'), 'Can move mount point into a similarly named but non-shared folder'); $shareManager->deleteShare($share); $userObject->delete(); |