Skip to content

Commit 87e4314

Browse files
authored
Merge pull request #60552 from nextcloud/backport/60542/stable30
[stable30] don't put hashed password in share api response
2 parents ba6e944 + 2fdcbdb commit 87e4314

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

232232
// "share_with" and "share_with_displayname" for passwords of link
233233
// shares was deprecated in Nextcloud 15, use "password" instead.
234-
$result['share_with'] = $share->getPassword();
234+
$result['share_with'] = $this->formatPasswordField($share->getPassword());
235235
$result['share_with_displayname'] = '(' . $this->l->t('Shared link') . ')';
236236

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

239239
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
240240

@@ -250,7 +250,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
250250
$result['token'] = $token;
251251
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
252252
$result['share_with'] = $share->getSharedWith();
253-
$result['password'] = $share->getPassword();
253+
$result['password'] = $this->formatPasswordField($share->getPassword());
254254
$result['password_expiration_time'] = $share->getPasswordExpirationTime() !== null ? $share->getPasswordExpirationTime()->format(\DateTime::ATOM) : null;
255255
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
256256
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
@@ -319,6 +319,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
319319
return $result;
320320
}
321321

322+
private function formatPasswordField(?string $password): ?string {
323+
return ($password === null) ? null : 'redacted';
324+
}
325+
322326
/**
323327
* Check if one of the users address books knows the exact property, if
324328
* 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
@@ -715,8 +715,8 @@ public function dataGetShare() {
715715
$expected = [
716716
'id' => 101,
717717
'share_type' => IShare::TYPE_LINK,
718-
'password' => 'password',
719-
'share_with' => 'password',
718+
'password' => 'redacted',
719+
'share_with' => 'redacted',
720720
'share_with_displayname' => '(Shared link)',
721721
'send_password_by_talk' => false,
722722
'uid_owner' => 'initiatorId',
@@ -4185,8 +4185,8 @@ public function dataFormatShare() {
41854185
'file_source' => 3,
41864186
'file_parent' => 1,
41874187
'file_target' => 'myTarget',
4188-
'password' => 'mypassword',
4189-
'share_with' => 'mypassword',
4188+
'password' => 'redacted',
4189+
'share_with' => 'redacted',
41904190
'share_with_displayname' => '(Shared link)',
41914191
'send_password_by_talk' => false,
41924192
'mail_send' => 0,
@@ -4244,8 +4244,8 @@ public function dataFormatShare() {
42444244
'file_source' => 3,
42454245
'file_parent' => 1,
42464246
'file_target' => 'myTarget',
4247-
'password' => 'mypassword',
4248-
'share_with' => 'mypassword',
4247+
'password' => 'redacted',
4248+
'share_with' => 'redacted',
42494249
'share_with_displayname' => '(Shared link)',
42504250
'send_password_by_talk' => true,
42514251
'mail_send' => 0,
@@ -4587,7 +4587,7 @@ public function dataFormatShare() {
45874587
'mail_send' => 0,
45884588
'mimetype' => 'myFolderMimeType',
45894589
'has_preview' => false,
4590-
'password' => 'password',
4590+
'password' => 'redacted',
45914591
'send_password_by_talk' => false,
45924592
'hide_download' => 0,
45934593
'can_edit' => false,
@@ -4643,7 +4643,7 @@ public function dataFormatShare() {
46434643
'mail_send' => 0,
46444644
'mimetype' => 'myFolderMimeType',
46454645
'has_preview' => false,
4646-
'password' => 'password',
4646+
'password' => 'redacted',
46474647
'send_password_by_talk' => true,
46484648
'hide_download' => 0,
46494649
'can_edit' => false,

0 commit comments

Comments
 (0)