Skip to content

Commit 97eceab

Browse files
Merge pull request #62097 from nextcloud/backport/61982/stable33
[stable33] fix(UserPlugin): Don't search for displayname when restricted
2 parents 7866a68 + e6a1f81 commit 97eceab

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

build/integration/features/bootstrap/ShareesContext.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected function resetAppConfigs() {
2626
$this->deleteServerConfig('core', 'shareapi_only_share_with_group_members');
2727
$this->deleteServerConfig('core', 'shareapi_only_share_with_group_members_exclude_group_list');
2828
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match');
29+
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_displayname');
2930
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_email');
3031
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn');
3132
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_user_id');

build/integration/sharees_features/sharees_user.feature

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,40 @@ Feature: sharees_user
394394
| Test One (Second displayname for user 1) | 0 | test1 | test1 |
395395
And "users" sharees returned is empty
396396

397+
Scenario: Search for displayname returns nothing without sharee enumeration and without full match displayname enumeration
398+
Given user "test" with displayname "foo" exists
399+
And user "test1" with displayname "Test One" exists
400+
And user "test2" with displayname "Test Two" exists
401+
And group "groupA" exists
402+
And user "test" belongs to group "groupA"
403+
And user "test1" belongs to group "groupA"
404+
And user "test2" belongs to group "groupA"
405+
And As an "test"
406+
And parameter "shareapi_allow_share_dialog_user_enumeration" of app "core" is set to "no"
407+
And parameter "shareapi_restrict_user_enumeration_full_match_displayname" of app "core" is set to "no"
408+
When getting sharees for
409+
| search | Test One |
410+
| itemType | file |
411+
Then the OCS status code should be "100"
412+
And the HTTP status code should be "200"
413+
And "exact users" sharees returned is empty
414+
And "users" sharees returned is empty
415+
416+
Scenario: Search for exact userid returns exact user without sharee enumeration and without full match displayname enumeration
417+
Given user "test" with displayname "foo" exists
418+
And user "test1" with displayname "Test One" exists
419+
And As an "test"
420+
And parameter "shareapi_allow_share_dialog_user_enumeration" of app "core" is set to "no"
421+
And parameter "shareapi_restrict_user_enumeration_full_match_displayname" of app "core" is set to "no"
422+
When getting sharees for
423+
| search | test1 |
424+
| itemType | file |
425+
Then the OCS status code should be "100"
426+
And the HTTP status code should be "200"
427+
And "exact users" sharees returned are
428+
| Test One | 0 | test1 | test1 |
429+
And "users" sharees returned is empty
430+
397431
Scenario: Search for exact userid with shared group returns exact user with sharee enumeration limited to group
398432
Given user "test" with displayname "foo" exists
399433
And user "test1" exists

lib/private/Collaboration/Collaborators/UserPlugin.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,19 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
8484
$shareeEnumerationFullMatch = $this->appConfig->getValueString('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
8585
if ($shareeEnumerationFullMatch && $search !== '') {
8686
$shareeEnumerationFullMatchUserId = $this->appConfig->getValueString('core', 'shareapi_restrict_user_enumeration_full_match_user_id', 'yes') === 'yes';
87+
$shareeEnumerationFullMatchDisplayName = $this->appConfig->getValueString('core', 'shareapi_restrict_user_enumeration_full_match_displayname', 'yes') === 'yes';
8788
$shareeEnumerationFullMatchEmail = $this->appConfig->getValueString('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
8889
$shareeEnumerationFullMatchIgnoreSecondDisplayName = $this->appConfig->getValueString('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no') === 'yes';
8990

9091
$lowerSearch = mb_strtolower($search);
9192

92-
// Re-use the results from earlier if possible
93-
$usersByDisplayName ??= $this->userManager->searchDisplayName($search, $limit, $offset);
94-
foreach ($usersByDisplayName as $user) {
95-
if ($user->isEnabled() && (mb_strtolower($user->getDisplayName()) === $lowerSearch || ($shareeEnumerationFullMatchIgnoreSecondDisplayName && trim(mb_strtolower(preg_replace('/ \(.*\)$/', '', $user->getDisplayName()))) === $lowerSearch))) {
96-
$users[$user->getUID()] = ['exact', $user];
93+
if ($shareeEnumerationFullMatchDisplayName) {
94+
// Re-use the results from earlier if possible
95+
$usersByDisplayName ??= $this->userManager->searchDisplayName($search, $limit, $offset);
96+
foreach ($usersByDisplayName as $user) {
97+
if ($user->isEnabled() && (mb_strtolower($user->getDisplayName()) === $lowerSearch || ($shareeEnumerationFullMatchIgnoreSecondDisplayName && trim(mb_strtolower(preg_replace('/ \(.*\)$/', '', $user->getDisplayName()))) === $lowerSearch))) {
98+
$users[$user->getUID()] = ['exact', $user];
99+
}
97100
}
98101
}
99102

0 commit comments

Comments
 (0)