Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate reshare permissions against actual path that the user tries to share #27820

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,9 @@ public function testGetShareFromSourceWithReshares() {
->setPermissions(19);
$share1 = $this->shareManager->createShare($share1);

$node2 = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get($this->filename);
$share2 = $this->shareManager->newShare();
$share2->setNode($node)
$share2->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
->setShareType(IShare::TYPE_USER)
Expand Down Expand Up @@ -633,7 +634,7 @@ public function testGetShareFromFolderReshares() {
$share1->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share1);

$node2 = $this->userFolder->get($this->folder.'/'.$this->filename);
$node2 = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get($this->folder.'/'.$this->filename);
$share2 = $this->shareManager->newShare();
$share2->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
Expand All @@ -643,7 +644,7 @@ public function testGetShareFromFolderReshares() {
$share2->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share2);

$node3 = $this->userFolder->get($this->folder.'/'.$this->subfolder.'/'.$this->filename);
$node3 = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get($this->folder.'/'.$this->subfolder.'/'.$this->filename);
$share3 = $this->shareManager->newShare();
$share3->setNode($node3)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
Expand Down Expand Up @@ -824,8 +825,9 @@ public function testGetShareMultipleSharedFolder() {
$share2->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share2);

$node2 = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get($this->folder . $this->subfolder);
$share3 = $this->shareManager->newShare();
$share3->setNode($node1)
$share3->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
Expand Down
30 changes: 30 additions & 0 deletions build/integration/sharing_features/sharing-v1-part3.feature
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,36 @@ Feature: sharing
Then the OCS status code should be "404"
And the HTTP status code should be "200"

Scenario: do allow to create links on a shared folder with two mountpoints
Given As an "admin"
And user "user0" exists
And user "user1" exists
And group "group1" exists
And user "user1" belongs to group "group1"
And user "user0" created a folder "/TMP"
And user "user0" created a folder "/TMP/SUB"
And As an "user0"
And creating a share with
| path | TMP |
| shareType | 1 |
| shareWith | group1 |
| permissions | 15 |
When As an "user1"
And accepting last share
And As an "user0"
And creating a share with
| path | TMP/SUB |
| shareType | 0 |
| shareWith | user1 |
| permissions | 31 |
When As an "user1"
And accepting last share
And creating a share with
| path | TMP/SUB |
| shareType | 3 |
Then the OCS status code should be "100"
And the HTTP status code should be "200"

Scenario: deleting file out of a share as recipient creates a backup for the owner
Given As an "admin"
And user "user0" exists
Expand Down
13 changes: 11 additions & 2 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\HintException;
use OCP\IConfig;
use OCP\IGroupManager;
Expand Down Expand Up @@ -292,10 +293,18 @@ protected function generalCreateChecks(IShare $share) {
$permissions = 0;

if (!$isFederatedShare && $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy()) {
$userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function ($mount) {
try {
$targetNode = $share->getTarget() ? $userFolder->get($share->getTarget()) : null;
} catch (NotFoundException $e) {
$targetNode = null;
}
$userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function ($mount) use ($share, $targetNode) {
// We need to filter since there might be other mountpoints that contain the file
// e.g. if the user has access to the same external storage that the file is originating from
return $mount->getStorage()->instanceOfStorage(ISharedStorage::class);
return $mount->getStorage()->instanceOfStorage(ISharedStorage::class) && (
$targetNode ? $targetNode->getPath() === $mount->getPath() :
$mount->getPath() === $share->getNode()->getPath()
);
});
$userMount = array_shift($userMounts);
if ($userMount === null) {
Expand Down