Skip to content

Commit 1efcc55

Browse files
committed
fix: forbid moving a folder into a subfolder of itself
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent c0b54c7 commit 1efcc55

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/private/Files/View.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
use OCP\Files\ConnectionLostException;
6060
use OCP\Files\EmptyFileNameException;
6161
use OCP\Files\FileNameTooLongException;
62+
use OCP\Files\ForbiddenException;
6263
use OCP\Files\InvalidCharacterInPathException;
6364
use OCP\Files\InvalidDirectoryException;
6465
use OCP\Files\InvalidPathException;
@@ -733,6 +734,11 @@ public function deleteAll($directory) {
733734
public function rename($source, $target) {
734735
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($source));
735736
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($target));
737+
738+
if (str_starts_with($absolutePath2 . '/', $absolutePath1)) {
739+
throw new ForbiddenException("Moving a folder into a child folder is forbidden", false);
740+
}
741+
736742
$targetParts = explode('/', $absolutePath2);
737743
$targetUser = $targetParts[1] ?? null;
738744
$result = false;

0 commit comments

Comments
 (0)