Skip to content

Commit 2805d54

Browse files
authored
Merge pull request #60551 from nextcloud/backport/60542/stable31
[stable31] don't put hashed password in share api response
2 parents 6d87a25 + e6421cb commit 2805d54

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
267267

268268
// "share_with" and "share_with_displayname" for passwords of link
269269
// shares was deprecated in Nextcloud 15, use "password" instead.
270-
$result['share_with'] = $share->getPassword();
270+
$result['share_with'] = $this->formatPasswordField($share->getPassword());
271271
$result['share_with_displayname'] = '(' . $this->l->t('Shared link') . ')';
272272

273-
$result['password'] = $share->getPassword();
273+
$result['password'] = $this->formatPasswordField($share->getPassword());
274274

275275
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
276276

@@ -286,7 +286,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
286286
$result['token'] = $token;
287287
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
288288
$result['share_with'] = $share->getSharedWith();
289-
$result['password'] = $share->getPassword();
289+
$result['password'] = $this->formatPasswordField($share->getPassword());
290290
$result['password_expiration_time'] = $share->getPasswordExpirationTime() !== null ? $share->getPasswordExpirationTime()->format(\DateTime::ATOM) : null;
291291
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
292292
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
@@ -355,6 +355,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
355355
return $result;
356356
}
357357

358+
private function formatPasswordField(?string $password): ?string {
359+
return ($password === null) ? null : 'redacted';
360+
}
361+
358362
/**
359363
* Check if one of the users address books knows the exact property, if
360364
* not we return the full name.

apps/files_sharing/tests/Controller/ShareAPIControllerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,8 @@ public function dataGetShare() {
787787
$expected = [
788788
'id' => 101,
789789
'share_type' => IShare::TYPE_LINK,
790-
'password' => 'password',
791-
'share_with' => 'password',
790+
'password' => 'redacted',
791+
'share_with' => 'redacted',
792792
'share_with_displayname' => '(Shared link)',
793793
'send_password_by_talk' => false,
794794
'uid_owner' => 'initiatorId',
@@ -4329,8 +4329,8 @@ public function dataFormatShare() {
43294329
'file_source' => 3,
43304330
'file_parent' => 1,
43314331
'file_target' => 'myTarget',
4332-
'password' => 'mypassword',
4333-
'share_with' => 'mypassword',
4332+
'password' => 'redacted',
4333+
'share_with' => 'redacted',
43344334
'share_with_displayname' => '(Shared link)',
43354335
'send_password_by_talk' => false,
43364336
'mail_send' => 0,
@@ -4388,8 +4388,8 @@ public function dataFormatShare() {
43884388
'file_source' => 3,
43894389
'file_parent' => 1,
43904390
'file_target' => 'myTarget',
4391-
'password' => 'mypassword',
4392-
'share_with' => 'mypassword',
4391+
'password' => 'redacted',
4392+
'share_with' => 'redacted',
43934393
'share_with_displayname' => '(Shared link)',
43944394
'send_password_by_talk' => true,
43954395
'mail_send' => 0,
@@ -4733,7 +4733,7 @@ public function dataFormatShare() {
47334733
'mail_send' => 0,
47344734
'mimetype' => 'myFolderMimeType',
47354735
'has_preview' => false,
4736-
'password' => 'password',
4736+
'password' => 'redacted',
47374737
'send_password_by_talk' => false,
47384738
'hide_download' => 0,
47394739
'can_edit' => false,
@@ -4789,7 +4789,7 @@ public function dataFormatShare() {
47894789
'mail_send' => 0,
47904790
'mimetype' => 'myFolderMimeType',
47914791
'has_preview' => false,
4792-
'password' => 'password',
4792+
'password' => 'redacted',
47934793
'send_password_by_talk' => true,
47944794
'hide_download' => 0,
47954795
'can_edit' => false,

0 commit comments

Comments
 (0)