Skip to content

Commit 49814f2

Browse files
Merge pull request #62732 from nextcloud/backport/62724/stable33
[stable33] fix(share-api-controller): add sanity check on canAccessShare for circle share types
2 parents 3e048ea + 64280b9 commit 49814f2

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

15541554
if ($share->getShareType() === IShare::TYPE_CIRCLE) {
1555-
// TODO: have a sanity check like above?
1556-
return true;
1555+
if (
1556+
Server::get(IAppManager::class)->isEnabledForUser('circles')
1557+
&& class_exists('\OCA\Circles\Api\v1\Circles')
1558+
) {
1559+
$hasCircleId = (str_ends_with($share->getSharedWith(), ']'));
1560+
$shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0);
1561+
$shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' '));
1562+
if ($shareWithLength === false) {
1563+
$sharedWith = substr($share->getSharedWith(), $shareWithStart);
1564+
} else {
1565+
$sharedWith = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
1566+
}
1567+
try {
1568+
$member = Circles::getMember($sharedWith, $this->userId, 1);
1569+
if ($member->getLevel() >= 1) {
1570+
return true;
1571+
}
1572+
return false;
1573+
} catch (\Exception $e) {
1574+
return false;
1575+
}
1576+
}
1577+
return false;
15571578
}
15581579

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

build/psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,7 @@
15281528
<UndefinedClass>
15291529
<code><![CDATA[Circles]]></code>
15301530
<code><![CDATA[Circles]]></code>
1531+
<code><![CDATA[Circles]]></code>
15311532
</UndefinedClass>
15321533
<UndefinedDocblockClass>
15331534
<code><![CDATA[$this->getRoomShareHelper()]]></code>

0 commit comments

Comments
 (0)