Skip to content

Commit 0c38333

Browse files
authored
Merge pull request #60549 from nextcloud/backport/60542/stable33
[stable33] don't put hashed password in share api response
2 parents d47f01a + 928b8f0 commit 0c38333

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

274274
// "share_with" and "share_with_displayname" for passwords of link
275275
// shares was deprecated in Nextcloud 15, use "password" instead.
276-
$result['share_with'] = $share->getPassword();
276+
$result['share_with'] = $this->formatPasswordField($share->getPassword());
277277
$result['share_with_displayname'] = '(' . $this->l->t('Shared link') . ')';
278278

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

281281
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
282282

@@ -292,7 +292,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
292292
$result['token'] = $token;
293293
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
294294
$result['share_with'] = $share->getSharedWith();
295-
$result['password'] = $share->getPassword();
295+
$result['password'] = $this->formatPasswordField($share->getPassword());
296296
$result['password_expiration_time'] = $share->getPasswordExpirationTime() !== null ? $share->getPasswordExpirationTime()->format(\DateTime::ATOM) : null;
297297
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
298298
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
@@ -351,6 +351,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
351351
return $result;
352352
}
353353

354+
private function formatPasswordField(?string $password): ?string {
355+
return ($password === null) ? null : 'redacted';
356+
}
357+
354358
/**
355359
* Check if one of the users address books knows the exact property, if
356360
* 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
@@ -796,8 +796,8 @@ public static function dataGetShare(): array {
796796
$expected = [
797797
'id' => 101,
798798
'share_type' => IShare::TYPE_LINK,
799-
'password' => 'password',
800-
'share_with' => 'password',
799+
'password' => 'redacted',
800+
'share_with' => 'redacted',
801801
'share_with_displayname' => '(Shared link)',
802802
'send_password_by_talk' => false,
803803
'uid_owner' => 'initiatorId',
@@ -4422,8 +4422,8 @@ public static function dataFormatShare(): array {
44224422
'file_source' => 3,
44234423
'file_parent' => 1,
44244424
'file_target' => 'myTarget',
4425-
'password' => 'mypassword',
4426-
'share_with' => 'mypassword',
4425+
'password' => 'redacted',
4426+
'share_with' => 'redacted',
44274427
'share_with_displayname' => '(Shared link)',
44284428
'send_password_by_talk' => false,
44294429
'mail_send' => 0,
@@ -4467,8 +4467,8 @@ public static function dataFormatShare(): array {
44674467
'file_source' => 3,
44684468
'file_parent' => 1,
44694469
'file_target' => 'myTarget',
4470-
'password' => 'mypassword',
4471-
'share_with' => 'mypassword',
4470+
'password' => 'redacted',
4471+
'share_with' => 'redacted',
44724472
'share_with_displayname' => '(Shared link)',
44734473
'send_password_by_talk' => true,
44744474
'mail_send' => 0,
@@ -4785,7 +4785,7 @@ public static function dataFormatShare(): array {
47854785
'mail_send' => 0,
47864786
'mimetype' => 'myFolderMimeType',
47874787
'has_preview' => false,
4788-
'password' => 'password',
4788+
'password' => 'redacted',
47894789
'send_password_by_talk' => false,
47904790
'hide_download' => 0,
47914791
'can_edit' => false,
@@ -4830,7 +4830,7 @@ public static function dataFormatShare(): array {
48304830
'mail_send' => 0,
48314831
'mimetype' => 'myFolderMimeType',
48324832
'has_preview' => false,
4833-
'password' => 'password',
4833+
'password' => 'redacted',
48344834
'send_password_by_talk' => true,
48354835
'hide_download' => 0,
48364836
'can_edit' => false,

0 commit comments

Comments
 (0)