Skip to content

Commit d6a7065

Browse files
Merge pull request #60542 from nextcloud/share-api-remove-hashed-pw
don't put hashed password in share api response
2 parents d24162f + b2494f2 commit d6a7065

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
@@ -807,8 +807,8 @@ public static function dataGetShare(): array {
807807
$expected = [
808808
'id' => '101',
809809
'share_type' => IShare::TYPE_LINK,
810-
'password' => 'password',
811-
'share_with' => 'password',
810+
'password' => 'redacted',
811+
'share_with' => 'redacted',
812812
'share_with_displayname' => '(Shared link)',
813813
'send_password_by_talk' => false,
814814
'uid_owner' => 'initiatorId',
@@ -4405,8 +4405,8 @@ public static function dataFormatShare(): array {
44054405
'file_source' => 3,
44064406
'file_parent' => 1,
44074407
'file_target' => 'myTarget',
4408-
'password' => 'mypassword',
4409-
'share_with' => 'mypassword',
4408+
'password' => 'redacted',
4409+
'share_with' => 'redacted',
44104410
'share_with_displayname' => '(Shared link)',
44114411
'send_password_by_talk' => false,
44124412
'mail_send' => 0,
@@ -4450,8 +4450,8 @@ public static function dataFormatShare(): array {
44504450
'file_source' => 3,
44514451
'file_parent' => 1,
44524452
'file_target' => 'myTarget',
4453-
'password' => 'mypassword',
4454-
'share_with' => 'mypassword',
4453+
'password' => 'redacted',
4454+
'share_with' => 'redacted',
44554455
'share_with_displayname' => '(Shared link)',
44564456
'send_password_by_talk' => true,
44574457
'mail_send' => 0,
@@ -4768,7 +4768,7 @@ public static function dataFormatShare(): array {
47684768
'mail_send' => 0,
47694769
'mimetype' => 'myFolderMimeType',
47704770
'has_preview' => false,
4771-
'password' => 'password',
4771+
'password' => 'redacted',
47724772
'send_password_by_talk' => false,
47734773
'hide_download' => 0,
47744774
'can_edit' => false,
@@ -4813,7 +4813,7 @@ public static function dataFormatShare(): array {
48134813
'mail_send' => 0,
48144814
'mimetype' => 'myFolderMimeType',
48154815
'has_preview' => false,
4816-
'password' => 'password',
4816+
'password' => 'redacted',
48174817
'send_password_by_talk' => true,
48184818
'hide_download' => 0,
48194819
'can_edit' => false,

0 commit comments

Comments
 (0)