Skip to content

Commit ca4ce5a

Browse files
Merge pull request #62730 from nextcloud/backport/62724/stable31
[stable31] fix(share-api-controller): add sanity check on canAccessShare for circle share types
2 parents cf5ea8e + 810109f commit ca4ce5a

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
@@ -1564,8 +1564,29 @@ protected function canAccessShare(IShare $share, bool $checkGroups = true): bool
15641564
}
15651565

15661566
if ($share->getShareType() === IShare::TYPE_CIRCLE) {
1567-
// TODO: have a sanity check like above?
1568-
return true;
1567+
if (
1568+
Server::get(IAppManager::class)->isEnabledForUser('circles')
1569+
&& class_exists('\OCA\Circles\Api\v1\Circles')
1570+
) {
1571+
$hasCircleId = (str_ends_with($share->getSharedWith(), ']'));
1572+
$shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0);
1573+
$shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' '));
1574+
if ($shareWithLength === false) {
1575+
$sharedWith = substr($share->getSharedWith(), $shareWithStart);
1576+
} else {
1577+
$sharedWith = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
1578+
}
1579+
try {
1580+
$member = Circles::getMember($sharedWith, $this->userId, 1);
1581+
if ($member->getLevel() >= 1) {
1582+
return true;
1583+
}
1584+
return false;
1585+
} catch (\Exception $e) {
1586+
return false;
1587+
}
1588+
}
1589+
return false;
15691590
}
15701591

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

build/psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@
857857
<UndefinedClass>
858858
<code><![CDATA[Circles]]></code>
859859
<code><![CDATA[Circles]]></code>
860+
<code><![CDATA[Circles]]></code>
860861
</UndefinedClass>
861862
<UndefinedDocblockClass>
862863
<code><![CDATA[$this->getRoomShareHelper()]]></code>

0 commit comments

Comments
 (0)