Skip to content

Commit 2eab703

Browse files
committed
fix: redact share token if share has more permissions than the current user
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 4f723ac commit 2eab703

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
236236
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
237237
}
238238

239+
$currentUserPermissions = $recipientNode ? $recipientNode->getPermissions() : Constants::PERMISSION_ALL;
240+
$userHasEnoughPermissions = ($currentUserPermissions & $share->getPermissions()) === $share->getPermissions();
241+
$token = $userHasEnoughPermissions ? $share->getToken() : null;
242+
239243
if ($share->getShareType() === IShare::TYPE_USER) {
240244
$sharedWith = $this->userManager->get($share->getSharedWith());
241245
$result['share_with'] = $share->getSharedWith();
@@ -262,6 +266,7 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
262266
$result['share_with'] = $share->getSharedWith();
263267
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
264268
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
269+
$url = ($token !== null) ? $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]) : null;
265270

266271
// "share_with" and "share_with_displayname" for passwords of link
267272
// shares was deprecated in Nextcloud 15, use "password" instead.
@@ -272,19 +277,19 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
272277

273278
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
274279

275-
$result['token'] = $share->getToken();
276-
$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
280+
$result['token'] = $token;
281+
$result['url'] = $url;
277282
} elseif ($share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP) {
278283
$result['share_with'] = $share->getSharedWith();
279284
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
280-
$result['token'] = $share->getToken();
285+
$result['token'] = $token;
281286
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
282287
$result['share_with'] = $share->getSharedWith();
283288
$result['password'] = $share->getPassword();
284289
$result['password_expiration_time'] = $share->getPasswordExpirationTime() !== null ? $share->getPasswordExpirationTime()->format(\DateTime::ATOM) : null;
285290
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
286291
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
287-
$result['token'] = $share->getToken();
292+
$result['token'] = $token;
288293
} elseif ($share->getShareType() === IShare::TYPE_CIRCLE) {
289294
// getSharedWith() returns either "name (type, owner)" or
290295
// "name (type, owner) [id]", depending on the Circles app version.

0 commit comments

Comments
 (0)