Skip to content

Commit c1801b0

Browse files
authored
Merge pull request #57041 from nextcloud/feat/full-match-displayname
feat: Allow to block full matches on the display name
2 parents 9d86b70 + 9bbb6de commit c1801b0

File tree

8 files changed

+29
-5
lines changed

8 files changed

+29
-5
lines changed

apps/settings/lib/Settings/Admin/Sharing.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function getForm() {
5555
'restrictUserEnumerationToPhone' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_phone'),
5656
'restrictUserEnumerationFullMatch' => $this->shareManager->allowEnumerationFullMatch(),
5757
'restrictUserEnumerationFullMatchUserId' => $this->shareManager->matchUserId(),
58+
'restrictUserEnumerationFullMatchDisplayname' => $this->shareManager->matchDisplayName(),
5859
'restrictUserEnumerationFullMatchEmail' => $this->shareManager->matchEmail(),
5960
'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->shareManager->ignoreSecondDisplayName(),
6061
'enforceLinksPassword' => Util::isPublicLinkPasswordRequired(false),

apps/settings/src/components/AdminSettingsSharingForm.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@
230230
<NcCheckboxRadioSwitch v-model="settings.restrictUserEnumerationFullMatchUserId">
231231
{{ t('settings', 'Also allow autocompletion on full match of the user ID') }}
232232
</NcCheckboxRadioSwitch>
233+
<NcCheckboxRadioSwitch v-model="settings.restrictUserEnumerationFullMatchDisplayname">
234+
{{ t('settings', 'Also allow autocompletion on full match of the display name') }}
235+
</NcCheckboxRadioSwitch>
233236
<NcCheckboxRadioSwitch v-model="settings.restrictUserEnumerationFullMatchEmail">
234237
{{ t('settings', 'Also allow autocompletion on full match of the user email') }}
235238
</NcCheckboxRadioSwitch>
@@ -291,6 +294,7 @@ interface IShareSettings {
291294
restrictUserEnumerationToPhone: boolean
292295
restrictUserEnumerationFullMatch: boolean
293296
restrictUserEnumerationFullMatchUserId: boolean
297+
restrictUserEnumerationFullMatchDisplayname: boolean
294298
restrictUserEnumerationFullMatchEmail: boolean
295299
restrictUserEnumerationFullMatchIgnoreSecondDN: boolean
296300
enforceLinksPassword: boolean

apps/settings/tests/Settings/Admin/SharingTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function testGetFormWithoutExcludedGroups(): void {
7777
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
7878
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
7979
['core', 'shareapi_restrict_user_enumeration_full_match_user_id', 'yes', 'yes'],
80+
['core', 'shareapi_restrict_user_enumeration_full_match_displayname', 'yes', 'yes'],
8081
['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
8182
['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
8283
['core', 'shareapi_enabled', 'yes', 'yes'],
@@ -120,6 +121,7 @@ public function testGetFormWithoutExcludedGroups(): void {
120121
'restrictUserEnumerationToPhone' => false,
121122
'restrictUserEnumerationFullMatch' => true,
122123
'restrictUserEnumerationFullMatchUserId' => true,
124+
'restrictUserEnumerationFullMatchDisplayname' => true,
123125
'restrictUserEnumerationFullMatchEmail' => true,
124126
'restrictUserEnumerationFullMatchIgnoreSecondDN' => false,
125127
'enforceLinksPassword' => false,
@@ -172,6 +174,7 @@ public function testGetFormWithExcludedGroups(): void {
172174
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
173175
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
174176
['core', 'shareapi_restrict_user_enumeration_full_match_user_id', 'yes', 'yes'],
177+
['core', 'shareapi_restrict_user_enumeration_full_match_displayname', 'yes', 'yes'],
175178
['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
176179
['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
177180
['core', 'shareapi_enabled', 'yes', 'yes'],
@@ -217,6 +220,7 @@ public function testGetFormWithExcludedGroups(): void {
217220
'restrictUserEnumerationToPhone' => false,
218221
'restrictUserEnumerationFullMatch' => true,
219222
'restrictUserEnumerationFullMatchUserId' => true,
223+
'restrictUserEnumerationFullMatchDisplayname' => true,
220224
'restrictUserEnumerationFullMatchEmail' => true,
221225
'restrictUserEnumerationFullMatchIgnoreSecondDN' => false,
222226
'enforceLinksPassword' => false,

dist/settings-vue-settings-admin-sharing.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/settings-vue-settings-admin-sharing.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/private/Collaboration/Collaborators/UserPlugin.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class UserPlugin implements ISearchPlugin {
3131

3232
protected bool $shareeEnumerationFullMatchUserId;
3333

34+
protected bool $shareeEnumerationfullMatchDisplayname;
35+
3436
protected bool $shareeEnumerationFullMatchEmail;
3537

3638
protected bool $shareeEnumerationFullMatchIgnoreSecondDisplayName;
@@ -50,6 +52,7 @@ public function __construct(
5052
$this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
5153
$this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
5254
$this->shareeEnumerationFullMatchUserId = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_user_id', 'yes') === 'yes';
55+
$this->shareeEnumerationfullMatchDisplayname = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_displayname', 'yes') === 'yes';
5356
$this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
5457
$this->shareeEnumerationFullMatchIgnoreSecondDisplayName = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no') === 'yes';
5558

@@ -112,7 +115,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
112115
}
113116

114117
// additionally we need to add full matches
115-
if ($this->shareeEnumerationFullMatch) {
118+
if ($this->shareeEnumerationFullMatch && $this->shareeEnumerationfullMatchDisplayname) {
116119
$usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
117120
foreach ($usersTmp as $user) {
118121
if ($user->isEnabled() && mb_strtolower($user->getDisplayName()) === mb_strtolower($search)) {
@@ -160,7 +163,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
160163
&& $lowerSearch !== ''
161164
&& (
162165
strtolower($uid) === $lowerSearch
163-
|| strtolower($userDisplayName) === $lowerSearch
166+
|| ($this->shareeEnumerationfullMatchDisplayname && strtolower($userDisplayName) === $lowerSearch)
164167
|| ($this->shareeEnumerationFullMatchIgnoreSecondDisplayName && trim(strtolower(preg_replace('/ \(.*\)$/', '', $userDisplayName))) === $lowerSearch)
165168
|| ($this->shareeEnumerationFullMatchEmail && strtolower($userEmail ?? '') === $lowerSearch)
166169
)

lib/private/Share20/Manager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,10 @@ public function matchUserId(): bool {
17421742
return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_user_id', 'yes') === 'yes';
17431743
}
17441744

1745+
public function matchDisplayName(): bool {
1746+
return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_displayname', 'yes') === 'yes';
1747+
}
1748+
17451749
#[Override]
17461750
public function ignoreSecondDisplayName(): bool {
17471751
return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no') === 'yes';

lib/public/Share/IManager.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,14 @@ public function matchEmail(): bool;
427427
*/
428428
public function matchUserId(): bool;
429429

430+
/**
431+
* When `allowEnumerationFullMatch` is enabled and `matchDisplayName` is set,
432+
* then also return results for full display name matches.
433+
*
434+
* @since 33.0.0
435+
*/
436+
public function matchDisplayName(): bool;
437+
430438
/**
431439
* When `allowEnumerationFullMatch` is enabled and `ignoreSecondDisplayName` is set,
432440
* then the search should ignore matches on the second displayname and only use the first.

0 commit comments

Comments
 (0)