Skip to content

Commit 54252ca

Browse files
authored
Merge pull request #59795 from nextcloud/backport/59792/stable31
[stable31] hide share token if share has more permissions than the current user
2 parents b5e7f17 + 6767e5a commit 54252ca

4 files changed

Lines changed: 44 additions & 7 deletions

File tree

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
class ShareAPIController extends OCSController {
7575

7676
private ?Node $lockedNode = null;
77+
/** @var array<bool> $trustedServerCache */
7778
private array $trustedServerCache = [];
7879

7980
/**
@@ -233,6 +234,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
233234
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
234235
}
235236

237+
$currentUserPermissions = $recipientNode?->getPermissions() ?? Constants::PERMISSION_ALL;
238+
$userHasEnoughPermissions = ($currentUserPermissions & $share->getPermissions()) === $share->getPermissions();
239+
$token = $userHasEnoughPermissions ? $share->getToken() : null;
240+
236241
if ($share->getShareType() === IShare::TYPE_USER) {
237242
$sharedWith = $this->userManager->get($share->getSharedWith());
238243
$result['share_with'] = $share->getSharedWith();
@@ -258,6 +263,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
258263
$result['share_with'] = $share->getSharedWith();
259264
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
260265
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
266+
$url = $token ? $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]) : null;
261267

262268
// "share_with" and "share_with_displayname" for passwords of link
263269
// shares was deprecated in Nextcloud 15, use "password" instead.
@@ -268,23 +274,23 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
268274

269275
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
270276

271-
$result['token'] = $share->getToken();
272-
$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
277+
$result['token'] = $token;
278+
$result['url'] = $url;
273279
} elseif ($share->getShareType() === IShare::TYPE_REMOTE) {
274280
$result['share_with'] = $share->getSharedWith();
275281
$result['share_with_displayname'] = $this->getCachedFederatedDisplayName($share->getSharedWith());
276-
$result['token'] = $share->getToken();
282+
$result['token'] = $token;
277283
} elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) {
278284
$result['share_with'] = $share->getSharedWith();
279285
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
280-
$result['token'] = $share->getToken();
286+
$result['token'] = $token;
281287
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
282288
$result['share_with'] = $share->getSharedWith();
283289
$result['password'] = $share->getPassword();
284290
$result['password_expiration_time'] = $share->getPasswordExpirationTime() !== null ? $share->getPasswordExpirationTime()->format(\DateTime::ATOM) : null;
285291
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
286292
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
287-
$result['token'] = $share->getToken();
293+
$result['token'] = $token;
288294
} elseif ($share->getShareType() === IShare::TYPE_CIRCLE) {
289295
// getSharedWith() returns either "name (type, owner)" or
290296
// "name (type, owner) [id]", depending on the Teams app version.

apps/files_sharing/lib/ResponseDefinitions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* token: ?string,
5555
* uid_file_owner: string,
5656
* uid_owner: string,
57-
* url?: string,
57+
* url?: string|null,
5858
* }
5959
*
6060
* @psalm-type Files_SharingDeletedShare = array{

apps/files_sharing/openapi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,8 @@
700700
"type": "string"
701701
},
702702
"url": {
703-
"type": "string"
703+
"type": "string",
704+
"nullable": true
704705
}
705706
}
706707
},

build/integration/sharing_features/sharing-v1-part2.feature

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,36 @@ Feature: sharing
2323
And User "user2" should be included in the response
2424
And User "user3" should not be included in the response
2525

26+
Scenario: getting all shares of a file with reshares with link share with less permissions
27+
Given user "user0" exists
28+
And user "user1" exists
29+
When as "user0" creating a share with
30+
| path | textfile0.txt |
31+
| shareType | 0 |
32+
| shareWith | user1 |
33+
| permissions | 17 |
34+
Then the OCS status code should be "100"
35+
And the HTTP status code should be "200"
36+
When as "user0" creating a share with
37+
| path | textfile0.txt |
38+
| shareType | 3 |
39+
| permissions | 19 |
40+
Then the OCS status code should be "100"
41+
And the HTTP status code should be "200"
42+
And last link share can be downloaded
43+
When As an "user1"
44+
And sending "GET" to "/apps/files_sharing/api/v1/shares?reshares=true&path=textfile0 (2).txt"
45+
Then the OCS status code should be "100"
46+
And the HTTP status code should be "200"
47+
And User "user1" should not be included in the response
48+
Then the list of returned shares has 1 shares
49+
And share 0 is returned with
50+
| share_type | 3 |
51+
| uid_owner | user0 |
52+
| token | |
53+
| url | |
54+
| permissions | 19 |
55+
2656
Scenario: getting all shares of a file with a received share after revoking the resharing rights
2757
Given user "user0" exists
2858
And user "user1" exists

0 commit comments

Comments
 (0)