Skip to content

Commit 1665420

Browse files
committed
fix(shareapi): Don't search for displayname when restricted
Assisted-by: ClaudeCode:claude-fable-5 Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
1 parent 35333ce commit 1665420

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
@@ -27,6 +27,7 @@ protected function resetAppConfigs() {
2727
$this->deleteServerConfig('core', 'shareapi_only_share_with_group_members');
2828
$this->deleteServerConfig('core', 'shareapi_only_share_with_group_members_exclude_group_list');
2929
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match');
30+
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_displayname');
3031
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_email');
3132
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn');
3233
$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
@@ -105,14 +105,17 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
105105
$shareeEnumerationFullMatch = $this->appConfig->getValueString('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
106106
if ($shareeEnumerationFullMatch && $search !== '') {
107107
$shareeEnumerationFullMatchUserId = $this->appConfig->getValueString('core', 'shareapi_restrict_user_enumeration_full_match_user_id', 'yes') === 'yes';
108+
$shareeEnumerationFullMatchDisplayName = $this->appConfig->getValueString('core', 'shareapi_restrict_user_enumeration_full_match_displayname', 'yes') === 'yes';
108109
$shareeEnumerationFullMatchEmail = $this->appConfig->getValueString('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
109110
$shareeEnumerationFullMatchIgnoreSecondDisplayName = $this->appConfig->getValueString('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no') === 'yes';
110111

111-
// Re-use the results from earlier if possible
112-
$usersByDisplayName ??= $this->userManager->searchDisplayName($search, $limit, $offset);
113-
foreach ($usersByDisplayName as $user) {
114-
if ($user->isEnabled() && (mb_strtolower($user->getDisplayName()) === $lowerSearch || ($shareeEnumerationFullMatchIgnoreSecondDisplayName && trim(mb_strtolower(preg_replace('/ \(.*\)$/', '', $user->getDisplayName()))) === $lowerSearch))) {
115-
$users[$user->getUID()] = ['exact', $user];
112+
if ($shareeEnumerationFullMatchDisplayName) {
113+
// Re-use the results from earlier if possible
114+
$usersByDisplayName ??= $this->userManager->searchDisplayName($search, $limit, $offset);
115+
foreach ($usersByDisplayName as $user) {
116+
if ($user->isEnabled() && (mb_strtolower($user->getDisplayName()) === $lowerSearch || ($shareeEnumerationFullMatchIgnoreSecondDisplayName && trim(mb_strtolower(preg_replace('/ \(.*\)$/', '', $user->getDisplayName()))) === $lowerSearch))) {
117+
$users[$user->getUID()] = ['exact', $user];
118+
}
116119
}
117120
}
118121

0 commit comments

Comments
 (0)