Skip to content

Commit 72c2aef

Browse files
committed
fix(contacts): Do not expose SAB in /contactsmenu
When hitting the `/contactsmenu/contacts` endpoint with the `dav.system_addressbook_exposed` config switch set to `"no"`, the system address book content is still listed in the response. This ensure that we do not expose unexpectedly the system address book. Signed-off-by: Louis Chmn <[email protected]>
1 parent c52e16d commit 72c2aef

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

apps/dav/lib/CardDAV/ContactsManager.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
use OCA\DAV\Db\PropertyMapper;
2929
use OCP\Contacts\IManager;
30+
use OCP\IAppConfig;
3031
use OCP\IL10N;
3132
use OCP\IURLGenerator;
3233

@@ -40,16 +41,20 @@ class ContactsManager {
4041
/** @var PropertyMapper */
4142
private $propertyMapper;
4243

44+
/** @var IAppConfig */
45+
private $appConfig;
46+
4347
/**
4448
* ContactsManager constructor.
4549
*
4650
* @param CardDavBackend $backend
4751
* @param IL10N $l10n
4852
*/
49-
public function __construct(CardDavBackend $backend, IL10N $l10n, PropertyMapper $propertyMapper) {
53+
public function __construct(CardDavBackend $backend, IL10N $l10n, PropertyMapper $propertyMapper, IAppConfig $appConfig) {
5054
$this->backend = $backend;
5155
$this->l10n = $l10n;
5256
$this->propertyMapper = $propertyMapper;
57+
$this->appConfig = $appConfig;
5358
}
5459

5560
/**
@@ -69,6 +74,11 @@ public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlG
6974
* @param IURLGenerator $urlGenerator
7075
*/
7176
public function setupSystemContactsProvider(IManager $cm, ?string $userId, IURLGenerator $urlGenerator) {
77+
$systemAddressBookExposed = $this->appConfig->getValueBool('dav', 'system_addressbook_exposed', true);
78+
if (!$systemAddressBookExposed) {
79+
return;
80+
}
81+
7282
$addressBooks = $this->backend->getAddressBooksForUser("principals/system/system");
7383
$this->register($cm, $addressBooks, $urlGenerator, $userId);
7484
}

apps/dav/tests/unit/CardDAV/ContactsManagerTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCA\DAV\CardDAV\ContactsManager;
3030
use OCA\DAV\Db\PropertyMapper;
3131
use OCP\Contacts\IManager;
32+
use OCP\IAppConfig;
3233
use OCP\IL10N;
3334
use OCP\IURLGenerator;
3435
use Test\TestCase;
@@ -37,17 +38,21 @@ class ContactsManagerTest extends TestCase {
3738
public function test(): void {
3839
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject $cm */
3940
$cm = $this->getMockBuilder(IManager::class)->disableOriginalConstructor()->getMock();
40-
$cm->expects($this->exactly(2))->method('registerAddressBook');
41+
$cm->expects($this->exactly(1))->method('registerAddressBook');
42+
/** @var IURLGenerator&MockObject $urlGenerator */
4143
$urlGenerator = $this->getMockBuilder(IURLGenerator::class)->disableOriginalConstructor()->getMock();
4244
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backEnd */
4345
$backEnd = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
4446
$backEnd->method('getAddressBooksForUser')->willReturn([
4547
['{DAV:}displayname' => 'Test address book', 'uri' => 'default'],
4648
]);
4749
$propertyMapper = $this->createMock(PropertyMapper::class);
50+
/** @var IAppConfig&MockObject $appConfig */
51+
$appConfig = $this->createMock(IAppConfig::class);
4852

53+
/** @var IL10N&MockObject $l */
4954
$l = $this->createMock(IL10N::class);
50-
$app = new ContactsManager($backEnd, $l, $propertyMapper);
55+
$app = new ContactsManager($backEnd, $l, $propertyMapper, $appConfig);
5156
$app->setupContactsProvider($cm, 'user01', $urlGenerator);
5257
}
5358
}

build/integration/features/contacts-menu.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,19 @@ Feature: contacts-menu
192192
And searching for contacts matching with "test"
193193
# Disabled because it regularly fails on drone:
194194
# Then the list of searched contacts has "0" contacts
195+
196+
Scenario: users cannot list other users from the system address book
197+
Given user "user0" exists
198+
And user "user1" exists
199+
And invoking occ with "config:app:set dav system_addressbook_exposed --value false"
200+
And Logging in using web as "user1"
201+
And searching for contacts matching with ""
202+
Then the list of searched contacts has "0" contacts
203+
And invoking occ with "config:app:delete dav system_addressbook_exposed"
204+
205+
Scenario: users can list other users from the system address book
206+
Given user "user0" exists
207+
And user "user1" exists
208+
And Logging in using web as "user1"
209+
And searching for contacts matching with ""
210+
Then the list of searched contacts has "1" contacts

0 commit comments

Comments
 (0)