diff options
author | Joas Schilling <coding@schilljs.com> | 2021-12-08 17:26:30 +0100 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2021-12-13 14:26:22 +0000 |
commit | 749935e91bdc74c7bf0f78107eecf754c831a200 (patch) | |
tree | 3d8d686b131f7e8b7c944a493f2595f74fd609eb | |
parent | 448ee8e30de63d6af679d2b43e198a87720e24fe (diff) | |
download | nextcloud-server-749935e91bdc74c7bf0f78107eecf754c831a200.tar.gz nextcloud-server-749935e91bdc74c7bf0f78107eecf754c831a200.zip |
Limit more contact searches
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | apps/federatedfilesharing/lib/Notifier.php | 7 | ||||
-rw-r--r-- | apps/files/lib/Activity/Provider.php | 7 | ||||
-rw-r--r-- | apps/files_sharing/lib/Activity/Providers/Base.php | 7 | ||||
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 8 | ||||
-rw-r--r-- | apps/files_sharing/tests/Controller/ShareAPIControllerTest.php | 12 | ||||
-rw-r--r-- | apps/sharebymail/lib/Activity.php | 7 | ||||
-rw-r--r-- | lib/private/Collaboration/Collaborators/RemotePlugin.php | 7 | ||||
-rw-r--r-- | lib/private/Contacts/ContactsMenu/ContactsStore.php | 5 | ||||
-rw-r--r-- | lib/private/Federation/CloudIdManager.php | 7 | ||||
-rw-r--r-- | lib/private/Share/Share.php | 7 |
10 files changed, 62 insertions, 12 deletions
diff --git a/apps/federatedfilesharing/lib/Notifier.php b/apps/federatedfilesharing/lib/Notifier.php index f365a14a13c..3f6d22d03aa 100644 --- a/apps/federatedfilesharing/lib/Notifier.php +++ b/apps/federatedfilesharing/lib/Notifier.php @@ -255,7 +255,12 @@ class Notifier implements INotifier { } } - $addressBookEntries = $this->contactsManager->search($federatedCloudId, ['CLOUD']); + $addressBookEntries = $this->contactsManager->search($federatedCloudId, ['CLOUD'], [ + 'limit' => 1, + 'enumeration' => false, + 'fullmatch' => false, + 'strict_search' => true, + ]); foreach ($addressBookEntries as $entry) { if (isset($entry['CLOUD'])) { foreach ($entry['CLOUD'] as $cloudID) { diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php index f50d9d6a42a..6d5618c4128 100644 --- a/apps/files/lib/Activity/Provider.php +++ b/apps/files/lib/Activity/Provider.php @@ -560,7 +560,12 @@ class Provider implements IProvider { return $this->displayNames[$search]; } - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD']); + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [ + 'limit' => 1, + 'enumeration' => false, + 'fullmatch' => false, + 'strict_search' => true, + ]); foreach ($addressBookContacts as $contact) { if (isset($contact['isLocalSystemBook'])) { continue; diff --git a/apps/files_sharing/lib/Activity/Providers/Base.php b/apps/files_sharing/lib/Activity/Providers/Base.php index 843a0c447f1..b8fee9f66f6 100644 --- a/apps/files_sharing/lib/Activity/Providers/Base.php +++ b/apps/files_sharing/lib/Activity/Providers/Base.php @@ -204,7 +204,12 @@ abstract class Base implements IProvider { return $this->displayNames[$search]; } - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD']); + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [ + 'limit' => 1, + 'enumeration' => false, + 'fullmatch' => false, + 'strict_search' => true, + ]); foreach ($addressBookContacts as $contact) { if (isset($contact['isLocalSystemBook'])) { continue; diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 8a3a8ab038f..108014923d5 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -333,8 +333,12 @@ class ShareAPIController extends OCSController { * @return string */ private function getDisplayNameFromAddressBook(string $query, string $property): string { - // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered - $result = \OC::$server->getContactsManager()->search($query, [$property]); + // FIXME: If we inject the contacts manager it gets initialized before any address books are registered + $result = \OC::$server->getContactsManager()->search($query, [$property], [ + 'limit' => 1, + 'enumeration' => false, + 'strict_search' => true, + ]); foreach ($result as $r) { foreach ($r[$property] as $value) { if ($value === $query && $r['FN']) { diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index 804a98f6d3f..5b45adc0a4c 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -4227,7 +4227,11 @@ class ShareAPIControllerTest extends TestCase { $cm->method('search') ->willReturnMap([ - ['user@server.com', ['CLOUD'], [], + ['user@server.com', ['CLOUD'], [ + 'limit' => 1, + 'enumeration' => false, + 'strict_search' => true, + ], [ [ 'CLOUD' => [ @@ -4237,7 +4241,11 @@ class ShareAPIControllerTest extends TestCase { ], ], ], - ['user@server.com', ['EMAIL'], [], + ['user@server.com', ['EMAIL'], [ + 'limit' => 1, + 'enumeration' => false, + 'strict_search' => true, + ], [ [ 'EMAIL' => [ diff --git a/apps/sharebymail/lib/Activity.php b/apps/sharebymail/lib/Activity.php index 23f036c4700..861969fca8a 100644 --- a/apps/sharebymail/lib/Activity.php +++ b/apps/sharebymail/lib/Activity.php @@ -363,7 +363,12 @@ class Activity implements IProvider { * @return string */ protected function getContactName($email) { - $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']); + $addressBookContacts = $this->contactsManager->search($email, ['EMAIL'], [ + 'limit' => 1, + 'enumeration' => false, + 'fullmatch' => false, + 'strict_search' => true, + ]); foreach ($addressBookContacts as $contact) { if (isset($contact['isLocalSystemBook'])) { diff --git a/lib/private/Collaboration/Collaborators/RemotePlugin.php b/lib/private/Collaboration/Collaborators/RemotePlugin.php index 3d9b1f9847a..e053465e83d 100644 --- a/lib/private/Collaboration/Collaborators/RemotePlugin.php +++ b/lib/private/Collaboration/Collaborators/RemotePlugin.php @@ -68,7 +68,12 @@ class RemotePlugin implements ISearchPlugin { $resultType = new SearchResultType('remotes'); // Search in contacts - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], ['limit' => $limit, 'offset' => $offset]); + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], [ + 'limit' => $limit, + 'offset' => $offset, + 'enumeration' => false, + 'fullmatch' => false, + ]); foreach ($addressBookContacts as $contact) { if (isset($contact['isLocalSystemBook'])) { continue; diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php index 69f26c7969f..5aa2c5ab1aa 100644 --- a/lib/private/Contacts/ContactsMenu/ContactsStore.php +++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php @@ -75,7 +75,10 @@ class ContactsStore implements IContactsStore { * @return IEntry[] */ public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null) { - $options = []; + $options = [ + 'enumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes', + 'fullmatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes', + ]; if ($limit !== null) { $options['limit'] = $limit; } diff --git a/lib/private/Federation/CloudIdManager.php b/lib/private/Federation/CloudIdManager.php index 0671a0bfa02..012be25b77f 100644 --- a/lib/private/Federation/CloudIdManager.php +++ b/lib/private/Federation/CloudIdManager.php @@ -83,7 +83,12 @@ class CloudIdManager implements ICloudIdManager { } protected function getDisplayNameFromContact(string $cloudId): ?string { - $addressBookEntries = $this->contactsManager->search($cloudId, ['CLOUD']); + $addressBookEntries = $this->contactsManager->search($cloudId, ['CLOUD'], [ + 'limit' => 1, + 'enumeration' => false, + 'fullmatch' => false, + 'strict_search' => true, + ]); foreach ($addressBookEntries as $entry) { if (isset($entry['CLOUD'])) { foreach ($entry['CLOUD'] as $cloudID) { diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 2d0d4f1cf87..5b310ac05c9 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -594,7 +594,12 @@ class Share extends Constants { $row['share_with_displayname'] = $shareWithUser === null ? $row['share_with'] : $shareWithUser->getDisplayName(); } elseif (isset($row['share_with']) && $row['share_with'] != '' && $row['share_type'] === IShare::TYPE_REMOTE) { - $addressBookEntries = \OC::$server->getContactsManager()->search($row['share_with'], ['CLOUD']); + $addressBookEntries = \OC::$server->getContactsManager()->search($row['share_with'], ['CLOUD'], [ + 'limit' => 1, + 'enumeration' => false, + 'fullmatch' => false, + 'strict_search' => true, + ]); foreach ($addressBookEntries as $entry) { foreach ($entry['CLOUD'] as $cloudID) { if ($cloudID === $row['share_with']) { |