Skip to content

Commit dcf82dc

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 <louis@chmn.me>
1 parent 159ffe4 commit dcf82dc

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

apps/dav/lib/CardDAV/ContactsManager.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use OCA\DAV\Db\PropertyMapper;
1111
use OCP\Contacts\IManager;
12+
use OCP\IAppConfig;
1213
use OCP\IL10N;
1314
use OCP\IURLGenerator;
1415

@@ -23,6 +24,7 @@ public function __construct(
2324
private CardDavBackend $backend,
2425
private IL10N $l10n,
2526
private PropertyMapper $propertyMapper,
27+
private IAppConfig $appConfig,
2628
) {
2729
}
2830

@@ -43,6 +45,11 @@ public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlG
4345
* @param IURLGenerator $urlGenerator
4446
*/
4547
public function setupSystemContactsProvider(IManager $cm, ?string $userId, IURLGenerator $urlGenerator) {
48+
$systemAddressBookExposed = $this->appConfig->getValueBool('dav', 'system_addressbook_exposed', true);
49+
if (!$systemAddressBookExposed) {
50+
return;
51+
}
52+
4653
$addressBooks = $this->backend->getAddressBooksForUser('principals/system/system');
4754
$this->register($cm, $addressBooks, $urlGenerator, $userId);
4855
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCA\DAV\CardDAV\ContactsManager;
1212
use OCA\DAV\Db\PropertyMapper;
1313
use OCP\Contacts\IManager;
14+
use OCP\IAppConfig;
1415
use OCP\IL10N;
1516
use OCP\IURLGenerator;
1617
use Test\TestCase;
@@ -19,17 +20,21 @@ class ContactsManagerTest extends TestCase {
1920
public function test(): void {
2021
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject $cm */
2122
$cm = $this->getMockBuilder(IManager::class)->disableOriginalConstructor()->getMock();
22-
$cm->expects($this->exactly(2))->method('registerAddressBook');
23+
$cm->expects($this->exactly(1))->method('registerAddressBook');
24+
/** @var IURLGenerator&MockObject $urlGenerator */
2325
$urlGenerator = $this->getMockBuilder(IURLGenerator::class)->disableOriginalConstructor()->getMock();
2426
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backEnd */
2527
$backEnd = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
2628
$backEnd->method('getAddressBooksForUser')->willReturn([
2729
['{DAV:}displayname' => 'Test address book', 'uri' => 'default'],
2830
]);
2931
$propertyMapper = $this->createMock(PropertyMapper::class);
32+
/** @var IAppConfig&MockObject $appConfig */
33+
$appConfig = $this->createMock(IAppConfig::class);
3034

35+
/** @var IL10N&MockObject $l */
3136
$l = $this->createMock(IL10N::class);
32-
$app = new ContactsManager($backEnd, $l, $propertyMapper);
37+
$app = new ContactsManager($backEnd, $l, $propertyMapper, $appConfig);
3338
$app->setupContactsProvider($cm, 'user01', $urlGenerator);
3439
}
3540
}

build/integration/features/contacts-menu.feature

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

0 commit comments

Comments
 (0)