Skip to content

Commit d2f0cad

Browse files
authored
Merge pull request #60550 from nextcloud/backport/60542/stable32
[stable32] don't put hashed password in share api response
2 parents 42a11c3 + d11fb91 commit d2f0cad

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

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

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

279279
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
280280

@@ -290,7 +290,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
290290
$result['token'] = $token;
291291
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
292292
$result['share_with'] = $share->getSharedWith();
293-
$result['password'] = $share->getPassword();
293+
$result['password'] = $this->formatPasswordField($share->getPassword());
294294
$result['password_expiration_time'] = $share->getPasswordExpirationTime() !== null ? $share->getPasswordExpirationTime()->format(\DateTime::ATOM) : null;
295295
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
296296
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
@@ -359,6 +359,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
359359
return $result;
360360
}
361361

362+
private function formatPasswordField(?string $password): ?string {
363+
return ($password === null) ? null : 'redacted';
364+
}
365+
362366
/**
363367
* Check if one of the users address books knows the exact property, if
364368
* 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 function dataGetShare() {
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',
@@ -4380,8 +4380,8 @@ public function dataFormatShare() {
43804380
'file_source' => 3,
43814381
'file_parent' => 1,
43824382
'file_target' => 'myTarget',
4383-
'password' => 'mypassword',
4384-
'share_with' => 'mypassword',
4383+
'password' => 'redacted',
4384+
'share_with' => 'redacted',
43854385
'share_with_displayname' => '(Shared link)',
43864386
'send_password_by_talk' => false,
43874387
'mail_send' => 0,
@@ -4439,8 +4439,8 @@ public function dataFormatShare() {
44394439
'file_source' => 3,
44404440
'file_parent' => 1,
44414441
'file_target' => 'myTarget',
4442-
'password' => 'mypassword',
4443-
'share_with' => 'mypassword',
4442+
'password' => 'redacted',
4443+
'share_with' => 'redacted',
44444444
'share_with_displayname' => '(Shared link)',
44454445
'send_password_by_talk' => true,
44464446
'mail_send' => 0,
@@ -4784,7 +4784,7 @@ public function dataFormatShare() {
47844784
'mail_send' => 0,
47854785
'mimetype' => 'myFolderMimeType',
47864786
'has_preview' => false,
4787-
'password' => 'password',
4787+
'password' => 'redacted',
47884788
'send_password_by_talk' => false,
47894789
'hide_download' => 0,
47904790
'can_edit' => false,
@@ -4840,7 +4840,7 @@ public function dataFormatShare() {
48404840
'mail_send' => 0,
48414841
'mimetype' => 'myFolderMimeType',
48424842
'has_preview' => false,
4843-
'password' => 'password',
4843+
'password' => 'redacted',
48444844
'send_password_by_talk' => true,
48454845
'hide_download' => 0,
48464846
'can_edit' => false,

0 commit comments

Comments
 (0)