Skip to content

Commit 1538b07

Browse files
committed
No DAV user enumeration if disabled
Fixes #9058 If the option to autocomplete users is disabled. We also should not enumerate the users on this endpoint. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 29eff7b commit 1538b07

4 files changed

Lines changed: 61 additions & 1 deletion

File tree

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
'OCA\\DAV\\CardDAV\\PhotoCache' => $baseDir . '/../lib/CardDAV/PhotoCache.php',
7474
'OCA\\DAV\\CardDAV\\Plugin' => $baseDir . '/../lib/CardDAV/Plugin.php',
7575
'OCA\\DAV\\CardDAV\\SyncService' => $baseDir . '/../lib/CardDAV/SyncService.php',
76+
'OCA\\DAV\\CardDAV\\SystemAddressbook' => $baseDir . '/../lib/CardDAV/SystemAddressbook.php',
7677
'OCA\\DAV\\CardDAV\\UserAddressBooks' => $baseDir . '/../lib/CardDAV/UserAddressBooks.php',
7778
'OCA\\DAV\\CardDAV\\Xml\\Groups' => $baseDir . '/../lib/CardDAV/Xml/Groups.php',
7879
'OCA\\DAV\\Command\\CreateAddressBook' => $baseDir . '/../lib/Command/CreateAddressBook.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class ComposerStaticInitDAV
8888
'OCA\\DAV\\CardDAV\\PhotoCache' => __DIR__ . '/..' . '/../lib/CardDAV/PhotoCache.php',
8989
'OCA\\DAV\\CardDAV\\Plugin' => __DIR__ . '/..' . '/../lib/CardDAV/Plugin.php',
9090
'OCA\\DAV\\CardDAV\\SyncService' => __DIR__ . '/..' . '/../lib/CardDAV/SyncService.php',
91+
'OCA\\DAV\\CardDAV\\SystemAddressbook' => __DIR__ . '/..' . '/../lib/CardDAV/SystemAddressbook.php',
9192
'OCA\\DAV\\CardDAV\\UserAddressBooks' => __DIR__ . '/..' . '/../lib/CardDAV/UserAddressBooks.php',
9293
'OCA\\DAV\\CardDAV\\Xml\\Groups' => __DIR__ . '/..' . '/../lib/CardDAV/Xml/Groups.php',
9394
'OCA\\DAV\\Command\\CreateAddressBook' => __DIR__ . '/..' . '/../lib/Command/CreateAddressBook.php',
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
5+
*
6+
* @author Roeland Jago Douma <roeland@famdouma.nl>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
namespace OCA\DAV\CardDAV;
26+
27+
use OCP\IConfig;
28+
use OCP\IL10N;
29+
use Sabre\CardDAV\Backend\BackendInterface;
30+
31+
class SystemAddressbook extends AddressBook {
32+
/** @var IConfig */
33+
private $config;
34+
35+
public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n, IConfig $config) {
36+
parent::__construct($carddavBackend, $addressBookInfo, $l10n);
37+
$this->config = $config;
38+
}
39+
40+
public function getChildren() {
41+
if ($this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes') {
42+
return [];
43+
}
44+
45+
return parent::getChildren();
46+
}
47+
}

apps/dav/lib/CardDAV/UserAddressBooks.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@
2222
*/
2323
namespace OCA\DAV\CardDAV;
2424

25+
use OCP\IConfig;
2526
use OCP\IL10N;
2627

2728
class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
2829

2930
/** @var IL10N */
3031
protected $l10n;
3132

33+
/** @var IConfig */
34+
protected $config;
35+
3236
/**
3337
* Returns a list of addressbooks
3438
*
@@ -38,11 +42,18 @@ function getChildren() {
3842
if ($this->l10n === null) {
3943
$this->l10n = \OC::$server->getL10N('dav');
4044
}
45+
if ($this->config === null) {
46+
$this->config = \OC::$server->getConfig();
47+
}
4148

4249
$addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri);
4350
$objects = [];
4451
foreach($addressBooks as $addressBook) {
45-
$objects[] = new AddressBook($this->carddavBackend, $addressBook, $this->l10n);
52+
if ($addressBook['principaluri'] === 'principals/system/system') {
53+
$objects[] = new SystemAddressbook($this->carddavBackend, $addressBook, $this->l10n, $this->config);
54+
} else {
55+
$objects[] = new AddressBook($this->carddavBackend, $addressBook, $this->l10n);
56+
}
4657
}
4758
return $objects;
4859

0 commit comments

Comments
 (0)