Skip to content

Commit 8a92a21

Browse files
committed
Limit more contact searches
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent ac773ea commit 8a92a21

9 files changed

Lines changed: 55 additions & 11 deletions

File tree

apps/federatedfilesharing/lib/Notifier.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,12 @@ protected function getDisplayNameFromContact($federatedCloudId) {
255255
}
256256
}
257257

258-
$addressBookEntries = $this->contactsManager->search($federatedCloudId, ['CLOUD']);
258+
$addressBookEntries = $this->contactsManager->search($federatedCloudId, ['CLOUD'], [
259+
'limit' => 1,
260+
'enumeration' => false,
261+
'fullmatch' => false,
262+
'strict_search' => true,
263+
]);
259264
foreach ($addressBookEntries as $entry) {
260265
if (isset($entry['CLOUD'])) {
261266
foreach ($entry['CLOUD'] as $cloudID) {

apps/files/lib/Activity/Provider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,12 @@ protected function getDisplayNameFromAddressBook(string $search): string {
560560
return $this->displayNames[$search];
561561
}
562562

563-
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD']);
563+
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [
564+
'limit' => 1,
565+
'enumeration' => false,
566+
'fullmatch' => false,
567+
'strict_search' => true,
568+
]);
564569
foreach ($addressBookContacts as $contact) {
565570
if (isset($contact['isLocalSystemBook'])) {
566571
continue;

apps/files_sharing/lib/Activity/Providers/Base.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,12 @@ protected function getDisplayNameFromAddressBook(string $search): string {
203203
return $this->displayNames[$search];
204204
}
205205

206-
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD']);
206+
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [
207+
'limit' => 1,
208+
'enumeration' => false,
209+
'fullmatch' => false,
210+
'strict_search' => true,
211+
]);
207212
foreach ($addressBookContacts as $contact) {
208213
if (isset($contact['isLocalSystemBook'])) {
209214
continue;

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,12 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
334334
* @return string
335335
*/
336336
private function getDisplayNameFromAddressBook(string $query, string $property): string {
337-
// FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered
338-
$result = \OC::$server->getContactsManager()->search($query, [$property]);
337+
// FIXME: If we inject the contacts manager it gets initialized before any address books are registered
338+
$result = \OC::$server->getContactsManager()->search($query, [$property], [
339+
'limit' => 1,
340+
'enumeration' => false,
341+
'strict_search' => true,
342+
]);
339343
foreach ($result as $r) {
340344
foreach ($r[$property] as $value) {
341345
if ($value === $query && $r['FN']) {

apps/sharebymail/lib/Activity.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,12 @@ protected function generateUserParameter($uid) {
362362
* @return string
363363
*/
364364
protected function getContactName($email) {
365-
$addressBookContacts = $this->contactsManager->search($email, ['EMAIL']);
365+
$addressBookContacts = $this->contactsManager->search($email, ['EMAIL'], [
366+
'limit' => 1,
367+
'enumeration' => false,
368+
'fullmatch' => false,
369+
'strict_search' => true,
370+
]);
366371

367372
foreach ($addressBookContacts as $contact) {
368373
if (isset($contact['isLocalSystemBook'])) {

lib/private/Collaboration/Collaborators/RemotePlugin.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
6767
$resultType = new SearchResultType('remotes');
6868

6969
// Search in contacts
70-
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], ['limit' => $limit, 'offset' => $offset]);
70+
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], [
71+
'limit' => $limit,
72+
'offset' => $offset,
73+
'enumeration' => false,
74+
'fullmatch' => false,
75+
]);
7176
foreach ($addressBookContacts as $contact) {
7277
if (isset($contact['isLocalSystemBook'])) {
7378
continue;

lib/private/Contacts/ContactsMenu/ContactsStore.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ public function __construct(
9696
* @return IEntry[]
9797
*/
9898
public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null) {
99-
$options = [];
99+
$options = [
100+
'enumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes',
101+
'fullmatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes',
102+
];
100103
if ($limit !== null) {
101104
$options['limit'] = $limit;
102105
}
@@ -270,7 +273,9 @@ public function findOne(IUser $user, $shareType, $shareWith) {
270273
return null;
271274
}
272275

273-
$contacts = $this->contactsManager->search($shareWith, $filter);
276+
$contacts = $this->contactsManager->search($shareWith, $filter, [
277+
'strict_search' => true,
278+
]);
274279
$match = null;
275280

276281
foreach ($contacts as $contact) {

lib/private/Federation/CloudIdManager.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ public function resolveCloudId(string $cloudId): ICloudId {
9090
}
9191

9292
protected function getDisplayNameFromContact(string $cloudId): ?string {
93-
$addressBookEntries = $this->contactsManager->search($cloudId, ['CLOUD']);
93+
$addressBookEntries = $this->contactsManager->search($cloudId, ['CLOUD'], [
94+
'limit' => 1,
95+
'enumeration' => false,
96+
'fullmatch' => false,
97+
'strict_search' => true,
98+
]);
9499
foreach ($addressBookEntries as $entry) {
95100
if (isset($entry['CLOUD'])) {
96101
foreach ($entry['CLOUD'] as $cloudID) {

lib/private/Share/Share.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,12 @@ public static function getItems($itemType, $item = null, $shareType = null, $sha
593593
$row['share_with_displayname'] = $shareWithUser === null ? $row['share_with'] : $shareWithUser->getDisplayName();
594594
} elseif (isset($row['share_with']) && $row['share_with'] != '' &&
595595
$row['share_type'] === IShare::TYPE_REMOTE) {
596-
$addressBookEntries = \OC::$server->getContactsManager()->search($row['share_with'], ['CLOUD']);
596+
$addressBookEntries = \OC::$server->getContactsManager()->search($row['share_with'], ['CLOUD'], [
597+
'limit' => 1,
598+
'enumeration' => false,
599+
'fullmatch' => false,
600+
'strict_search' => true,
601+
]);
597602
foreach ($addressBookEntries as $entry) {
598603
foreach ($entry['CLOUD'] as $cloudID) {
599604
if ($cloudID === $row['share_with']) {

0 commit comments

Comments
 (0)