Skip to content

Commit 08af926

Browse files
authored
Merge pull request #59798 from nextcloud/backport/59792/stable29
[stable29] hide share token if share has more permissions than the current user
2 parents 7122a89 + a331021 commit 08af926

4 files changed

Lines changed: 43 additions & 7 deletions

File tree

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
228228
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
229229
}
230230

231+
$currentUserPermissions = $recipientNode?->getPermissions() ?? Constants::PERMISSION_ALL;
232+
$userHasEnoughPermissions = ($currentUserPermissions & $share->getPermissions()) === $share->getPermissions();
233+
$token = $userHasEnoughPermissions ? $share->getToken() : null;
234+
231235
if ($share->getShareType() === IShare::TYPE_USER) {
232236
$sharedWith = $this->userManager->get($share->getSharedWith());
233237
$result['share_with'] = $share->getSharedWith();
@@ -253,6 +257,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
253257
$result['share_with'] = $share->getSharedWith();
254258
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
255259
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
260+
$url = ($token !== null) ? $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]) : null;
256261

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

264269
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
265270

266-
$result['token'] = $share->getToken();
267-
$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
271+
$result['token'] = $token;
272+
$result['url'] = $url;
268273
} elseif ($share->getShareType() === IShare::TYPE_REMOTE) {
269274
$result['share_with'] = $share->getSharedWith();
270275
$result['share_with_displayname'] = $this->getCachedFederatedDisplayName($share->getSharedWith());
271-
$result['token'] = $share->getToken();
276+
$result['token'] = $token;
272277
} elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) {
273278
$result['share_with'] = $share->getSharedWith();
274279
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
275-
$result['token'] = $share->getToken();
280+
$result['token'] = $token;
276281
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
277282
$result['share_with'] = $share->getSharedWith();
278283
$result['password'] = $share->getPassword();
279284
$result['password_expiration_time'] = $share->getPasswordExpirationTime() !== null ? $share->getPasswordExpirationTime()->format(\DateTime::ATOM) : null;
280285
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
281286
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
282-
$result['token'] = $share->getToken();
287+
$result['token'] = $token;
283288
} elseif ($share->getShareType() === IShare::TYPE_CIRCLE) {
284289
// getSharedWith() returns either "name (type, owner)" or
285290
// "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
@@ -70,7 +70,7 @@
7070
* token: ?string,
7171
* uid_file_owner: string,
7272
* uid_owner: string,
73-
* url?: string,
73+
* url?: string|null,
7474
* }
7575
*
7676
* @psalm-type Files_SharingDeletedShare = array{

apps/files_sharing/openapi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,8 @@
694694
"type": "string"
695695
},
696696
"url": {
697-
"type": "string"
697+
"type": "string",
698+
"nullable": true
698699
}
699700
}
700701
},

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

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

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

0 commit comments

Comments
 (0)