Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions apps/dav/lib/Connector/Sabre/Principal.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ protected function searchUserPrincipals(array $searchProperties, $test = 'allof'
$limitEnumerationGroup = $this->shareManager->limitEnumerationToGroups();
$limitEnumerationPhone = $this->shareManager->limitEnumerationToPhone();
$allowEnumerationFullMatch = $this->shareManager->allowEnumerationFullMatch();
$ignoreSecondDisplayName = $this->shareManager->ignoreSecondDisplayName();
$matchEmail = $this->shareManager->matchEmail();

// If sharing is restricted to group members only,
// return only members that have groups in common
Expand Down Expand Up @@ -298,7 +300,7 @@ protected function searchUserPrincipals(array $searchProperties, $test = 'allof'
switch ($prop) {
case '{http://sabredav.org/ns}email-address':
if (!$allowEnumeration) {
if ($allowEnumerationFullMatch) {
if ($allowEnumerationFullMatch && $matchEmail) {
$users = $this->userManager->getByEmail($value);
} else {
$users = [];
Expand Down Expand Up @@ -349,8 +351,9 @@ protected function searchUserPrincipals(array $searchProperties, $test = 'allof'
if ($allowEnumerationFullMatch) {
$lowerSearch = strtolower($value);
$users = $this->userManager->searchDisplayName($value, $searchLimit);
$users = \array_filter($users, static function (IUser $user) use ($lowerSearch) {
return strtolower($user->getDisplayName()) === $lowerSearch;
$users = \array_filter($users, static function (IUser $user) use ($lowerSearch, $ignoreSecondDisplayName) {
$lowerDisplayName = strtolower($user->getDisplayName());
return $lowerDisplayName === $lowerSearch || ($ignoreSecondDisplayName && trim(preg_replace('/ \(.*\)$/', '', $lowerDisplayName)) === $lowerSearch);
});
} else {
$users = [];
Expand Down
4 changes: 4 additions & 0 deletions apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@ public function testSearchPrincipalWithEnumerationDisabledEmail(): void {
->method('allowEnumerationFullMatch')
->willReturn(true);

$this->shareManager->expects($this->once())
->method('matchEmail')
->willReturn(true);

$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('getDisplayName')->willReturn('User 2');
Expand Down
8 changes: 8 additions & 0 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,14 @@ public function allowEnumerationFullMatch(): bool {
return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
}

public function matchEmail(): bool {
return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
}

public function ignoreSecondDisplayName(): bool {
return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name', 'no') === 'yes';
}

public function currentUserCanEnumerateTargetUser(?IUser $currentUser, IUser $targetUser): bool {
if ($this->allowEnumerationFullMatch()) {
return true;
Expand Down
16 changes: 16 additions & 0 deletions lib/public/Share/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,22 @@ public function limitEnumerationToPhone(): bool;
*/
public function allowEnumerationFullMatch(): bool;

/**
* Check if the search should match the email
*
* @return bool
* @since 25.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

24.0.1

Copy link
Contributor Author

@artonge artonge Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix here: #32739

*/
public function matchEmail(): bool;

/**
* Check if the search should ignore the second in parentheses display name if there is any
*
* @return bool
* @since 25.0.0
*/
public function ignoreSecondDisplayName(): bool;

/**
* Check if the current user can enumerate the target user
*
Expand Down