Skip to content

Commit 5479f63

Browse files
cristianscheidartonge
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 bff9aaf commit 5479f63

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

15271527
if ($share->getShareType() === IShare::TYPE_CIRCLE) {
1528-
// TODO: have a sanity check like above?
1529-
return true;
1528+
if (
1529+
Server::get(IAppManager::class)->isEnabledForUser('circles')
1530+
&& class_exists('\OCA\Circles\Api\v1\Circles')
1531+
) {
1532+
$hasCircleId = (str_ends_with($share->getSharedWith(), ']'));
1533+
$shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0);
1534+
$shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' '));
1535+
if ($shareWithLength === false) {
1536+
$sharedWith = substr($share->getSharedWith(), $shareWithStart);
1537+
} else {
1538+
$sharedWith = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
1539+
}
1540+
try {
1541+
$member = Circles::getMember($sharedWith, $this->userId, 1);
1542+
if ($member->getLevel() >= 1) {
1543+
return true;
1544+
}
1545+
return false;
1546+
} catch (\Exception $e) {
1547+
return false;
1548+
}
1549+
}
1550+
return false;
15301551
}
15311552

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

‎build/psalm-baseline.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,7 @@
16661666
<UndefinedClass>
16671667
<code><![CDATA[Circles]]></code>
16681668
<code><![CDATA[Circles]]></code>
1669+
<code><![CDATA[Circles]]></code>
16691670
</UndefinedClass>
16701671
</file>
16711672
<file src="apps/files_sharing/lib/Controller/ShareController.php">

0 commit comments

Comments
 (0)