Skip to content

Commit

Permalink
Merge pull request #45014 from nextcloud/forbid-moving-subfolder
Browse files Browse the repository at this point in the history
fix: forbid moving a folder into a subfolder of itself
  • Loading branch information
icewind1991 authored May 27, 2024
2 parents b8aef38 + 66d36bf commit d87c232
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCP\Files\ConnectionLostException;
use OCP\Files\EmptyFileNameException;
use OCP\Files\FileNameTooLongException;
use OCP\Files\ForbiddenException;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidDirectoryException;
use OCP\Files\InvalidPathException;
Expand Down Expand Up @@ -694,6 +695,11 @@ public function deleteAll($directory) {
public function rename($source, $target) {
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($source));
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($target));

if (str_starts_with($absolutePath2, $absolutePath1 . '/')) {
throw new ForbiddenException("Moving a folder into a child folder is forbidden", false);
}

$targetParts = explode('/', $absolutePath2);
$targetUser = $targetParts[1] ?? null;
$result = false;
Expand Down

0 comments on commit d87c232

Please sign in to comment.