Skip to content

Commit 902bdc9

Browse files
authored
Merge pull request #59797 from nextcloud/backport/59792/stable30
[stable30] hide share token if share has more permissions than the current user
2 parents ec7adce + 1b3c0ab commit 902bdc9

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
@@ -198,6 +198,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
198198
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
199199
}
200200

201+
$currentUserPermissions = $recipientNode?->getPermissions() ?? Constants::PERMISSION_ALL;
202+
$userHasEnoughPermissions = ($currentUserPermissions & $share->getPermissions()) === $share->getPermissions();
203+
$token = $userHasEnoughPermissions ? $share->getToken() : null;
204+
201205
if ($share->getShareType() === IShare::TYPE_USER) {
202206
$sharedWith = $this->userManager->get($share->getSharedWith());
203207
$result['share_with'] = $share->getSharedWith();
@@ -223,6 +227,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
223227
$result['share_with'] = $share->getSharedWith();
224228
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
225229
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
230+
$url = ($token !== null) ? $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]) : null;
226231

227232
// "share_with" and "share_with_displayname" for passwords of link
228233
// shares was deprecated in Nextcloud 15, use "password" instead.
@@ -233,23 +238,23 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
233238

234239
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
235240

236-
$result['token'] = $share->getToken();
237-
$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
241+
$result['token'] = $token;
242+
$result['url'] = $url;
238243
} elseif ($share->getShareType() === IShare::TYPE_REMOTE) {
239244
$result['share_with'] = $share->getSharedWith();
240245
$result['share_with_displayname'] = $this->getCachedFederatedDisplayName($share->getSharedWith());
241-
$result['token'] = $share->getToken();
246+
$result['token'] = $token;
242247
} elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) {
243248
$result['share_with'] = $share->getSharedWith();
244249
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
245-
$result['token'] = $share->getToken();
250+
$result['token'] = $token;
246251
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
247252
$result['share_with'] = $share->getSharedWith();
248253
$result['password'] = $share->getPassword();
249254
$result['password_expiration_time'] = $share->getPasswordExpirationTime() !== null ? $share->getPasswordExpirationTime()->format(\DateTime::ATOM) : null;
250255
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
251256
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
252-
$result['token'] = $share->getToken();
257+
$result['token'] = $token;
253258
} elseif ($share->getShareType() === IShare::TYPE_CIRCLE) {
254259
// getSharedWith() returns either "name (type, owner)" or
255260
// "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
@@ -53,7 +53,7 @@
5353
* token: ?string,
5454
* uid_file_owner: string,
5555
* uid_owner: string,
56-
* url?: string,
56+
* url?: string|null,
5757
* }
5858
*
5959
* @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
@@ -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)