Skip to content

Commit 1c94e3d

Browse files
Merge pull request #62729 from nextcloud/backport/62724/stable30
[stable30] fix(share-api-controller): add sanity check on canAccessShare for circle share types
2 parents f51c4f7 + 193a383 commit 1c94e3d

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,8 +1510,29 @@ protected function canAccessShare(\OCP\Share\IShare $share, bool $checkGroups =
15101510
}
15111511

15121512
if ($share->getShareType() === IShare::TYPE_CIRCLE) {
1513-
// TODO: have a sanity check like above?
1514-
return true;
1513+
if (
1514+
Server::get(IAppManager::class)->isEnabledForUser('circles')
1515+
&& class_exists('\OCA\Circles\Api\v1\Circles')
1516+
) {
1517+
$hasCircleId = (str_ends_with($share->getSharedWith(), ']'));
1518+
$shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0);
1519+
$shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' '));
1520+
if ($shareWithLength === false) {
1521+
$sharedWith = substr($share->getSharedWith(), $shareWithStart);
1522+
} else {
1523+
$sharedWith = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
1524+
}
1525+
try {
1526+
$member = Circles::getMember($sharedWith, $this->userId, 1);
1527+
if ($member->getLevel() >= 1) {
1528+
return true;
1529+
}
1530+
return false;
1531+
} catch (\Exception $e) {
1532+
return false;
1533+
}
1534+
}
1535+
return false;
15151536
}
15161537

15171538
if ($share->getShareType() === IShare::TYPE_ROOM) {

build/psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@
886886
<UndefinedClass>
887887
<code><![CDATA[\OCA\Circles\Api\v1\Circles]]></code>
888888
<code><![CDATA[\OCA\Circles\Api\v1\Circles]]></code>
889+
<code><![CDATA[\OCA\Circles\Api\v1\Circles]]></code>
889890
</UndefinedClass>
890891
<UndefinedDocblockClass>
891892
<code><![CDATA[$this->getRoomShareHelper()]]></code>

0 commit comments

Comments
 (0)