Skip to content

Commit a9e375e

Browse files
cristianscheidbackportbot[bot]
authored andcommitted
fix(share-api-controller): add sanity check on canAccessShare for circle
share types Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
1 parent 162edf7 commit a9e375e

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

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

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

build/psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,7 @@
15771577
<UndefinedClass>
15781578
<code><![CDATA[Circles]]></code>
15791579
<code><![CDATA[Circles]]></code>
1580+
<code><![CDATA[Circles]]></code>
15801581
</UndefinedClass>
15811582
<UndefinedDocblockClass>
15821583
<code><![CDATA[$this->getRoomShareHelper()]]></code>

0 commit comments

Comments
 (0)