From 64ca00925b0384592091cab3e596d5427c1c5517 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 2 Oct 2015 12:14:24 +0200 Subject: 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. --- lib/private/files/view.php | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'lib/private') 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; } /** -- cgit v1.2.3