diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-10-02 12:14:24 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-10-02 16:14:42 +0200 |
commit | 64ca00925b0384592091cab3e596d5427c1c5517 (patch) | |
tree | 27d98a697725a6e1130f08a2b111f72b6d8b9f77 /lib | |
parent | 3dec30d0e09128002f24f58b7ea042c42defce31 (diff) | |
download | nextcloud-server-64ca00925b0384592091cab3e596d5427c1c5517.tar.gz nextcloud-server-64ca00925b0384592091cab3e596d5427c1c5517.zip |
Prevent moving mount point into already shared folder (outgoing)
It is already not allowed to share a folder containing mount points /
incoming shares.
This fixes an issue that made it possible to bypass the check by moving
the incoming share mount point into an existing outgoing share folder.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files/view.php | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 95b688fef5c..c8dbc001f2d 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -1602,25 +1602,46 @@ class View { /** * check if it is allowed to move a mount point to a given target. - * It is not allowed to move a mount point into a different mount point + * It is not allowed to move a mount point into a different mount point or + * into an already shared folder * * @param string $target path * @return boolean */ private function isTargetAllowed($target) { - $result = false; - - list($targetStorage,) = \OC\Files\Filesystem::resolvePath($target); - if ($targetStorage->instanceOfStorage('\OCP\Files\IHomeStorage')) { - $result = true; - } else { + list($targetStorage, $targetInternalPath) = \OC\Files\Filesystem::resolvePath($target); + if (!$targetStorage->instanceOfStorage('\OCP\Files\IHomeStorage')) { \OCP\Util::writeLog('files', 'It is not allowed to move one mount point into another one', \OCP\Util::DEBUG); + return false; } - return $result; + // note: cannot use the view because the target is already locked + $fileId = (int)$targetStorage->getCache()->getId($targetInternalPath); + if ($fileId === -1) { + // target might not exist, need to check parent instead + $fileId = (int)$targetStorage->getCache()->getId(dirname($targetInternalPath)); + } + + // check if any of the parents were shared by the current owner (include collections) + $shares = \OCP\Share::getItemShared( + 'folder', + $fileId, + \OCP\Share::FORMAT_NONE, + null, + true + ); + + if (count($shares) > 0) { + \OCP\Util::writeLog('files', + 'It is not allowed to move one mount point into a shared folder', + \OCP\Util::DEBUG); + return false; + } + + return true; } /** |