Skip to content

Commit d14c96b

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 Chemineau <louis@chmn.me>
1 parent 9dfd6f1 commit d14c96b

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

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
@@ -12,6 +12,7 @@
1212
use OCA\DAV\CardDAV\ContactsManager;
1313
use OCA\DAV\Db\PropertyMapper;
1414
use OCP\Contacts\IManager;
15+
use OCP\IAppConfig;
1516
use OCP\IL10N;
1617
use OCP\IURLGenerator;
1718
use PHPUnit\Framework\MockObject\MockObject;
@@ -21,17 +22,21 @@ class ContactsManagerTest extends TestCase {
2122
public function test(): void {
2223
/** @var IManager&MockObject $cm */
2324
$cm = $this->createMock(IManager::class);
24-
$cm->expects($this->exactly(2))->method('registerAddressBook');
25+
$cm->expects($this->exactly(1))->method('registerAddressBook');
26+
/** @var IURLGenerator&MockObject $urlGenerator */
2527
$urlGenerator = $this->createMock(IURLGenerator::class);
2628
/** @var CardDavBackend&MockObject $backEnd */
2729
$backEnd = $this->createMock(CardDavBackend::class);
2830
$backEnd->method('getAddressBooksForUser')->willReturn([
2931
['{DAV:}displayname' => 'Test address book', 'uri' => 'default'],
3032
]);
3133
$propertyMapper = $this->createMock(PropertyMapper::class);
34+
/** @var IAppConfig&MockObject $appConfig */
35+
$appConfig = $this->createMock(IAppConfig::class);
3236

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

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 "1" 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 "2" contacts

0 commit comments

Comments
 (0)