Skip to content

Commit bfc5f4b

Browse files
authored
Merge pull request #60553 from nextcloud/backport/60542/stable29
[stable29] don't put hashed password in share api response
2 parents cb6be9a + ad5dee5 commit bfc5f4b

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
@@ -261,10 +261,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
261261

262262
// "share_with" and "share_with_displayname" for passwords of link
263263
// shares was deprecated in Nextcloud 15, use "password" instead.
264-
$result['share_with'] = $share->getPassword();
264+
$result['share_with'] = $this->formatPasswordField($share->getPassword());
265265
$result['share_with_displayname'] = '(' . $this->l->t('Shared link') . ')';
266266

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

269269
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
270270

@@ -280,7 +280,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
280280
$result['token'] = $token;
281281
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
282282
$result['share_with'] = $share->getSharedWith();
283-
$result['password'] = $share->getPassword();
283+
$result['password'] = $this->formatPasswordField($share->getPassword());
284284
$result['password_expiration_time'] = $share->getPasswordExpirationTime() !== null ? $share->getPasswordExpirationTime()->format(\DateTime::ATOM) : null;
285285
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
286286
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
@@ -349,6 +349,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
349349
return $result;
350350
}
351351

352+
private function formatPasswordField(?string $password): ?string {
353+
return ($password === null) ? null : 'redacted';
354+
}
355+
352356
/**
353357
* Check if one of the users address books knows the exact property, if
354358
* 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
@@ -733,8 +733,8 @@ public function dataGetShare() {
733733
$expected = [
734734
'id' => 101,
735735
'share_type' => IShare::TYPE_LINK,
736-
'password' => 'password',
737-
'share_with' => 'password',
736+
'password' => 'redacted',
737+
'share_with' => 'redacted',
738738
'share_with_displayname' => '(Shared link)',
739739
'send_password_by_talk' => false,
740740
'uid_owner' => 'initiatorId',
@@ -4189,8 +4189,8 @@ public function dataFormatShare() {
41894189
'file_source' => 3,
41904190
'file_parent' => 1,
41914191
'file_target' => 'myTarget',
4192-
'password' => 'mypassword',
4193-
'share_with' => 'mypassword',
4192+
'password' => 'redacted',
4193+
'share_with' => 'redacted',
41944194
'share_with_displayname' => '(Shared link)',
41954195
'send_password_by_talk' => false,
41964196
'mail_send' => 0,
@@ -4248,8 +4248,8 @@ public function dataFormatShare() {
42484248
'file_source' => 3,
42494249
'file_parent' => 1,
42504250
'file_target' => 'myTarget',
4251-
'password' => 'mypassword',
4252-
'share_with' => 'mypassword',
4251+
'password' => 'redacted',
4252+
'share_with' => 'redacted',
42534253
'share_with_displayname' => '(Shared link)',
42544254
'send_password_by_talk' => true,
42554255
'mail_send' => 0,
@@ -4591,7 +4591,7 @@ public function dataFormatShare() {
45914591
'mail_send' => 0,
45924592
'mimetype' => 'myFolderMimeType',
45934593
'has_preview' => false,
4594-
'password' => 'password',
4594+
'password' => 'redacted',
45954595
'send_password_by_talk' => false,
45964596
'hide_download' => 0,
45974597
'can_edit' => false,
@@ -4647,7 +4647,7 @@ public function dataFormatShare() {
46474647
'mail_send' => 0,
46484648
'mimetype' => 'myFolderMimeType',
46494649
'has_preview' => false,
4650-
'password' => 'password',
4650+
'password' => 'redacted',
46514651
'send_password_by_talk' => true,
46524652
'hide_download' => 0,
46534653
'can_edit' => false,

0 commit comments

Comments
 (0)