Skip to content

Commit 454fbc0

Browse files
artongebackportbot[bot]
authored andcommitted
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> [skip ci]
1 parent 159ffe4 commit 454fbc0

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
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: 5 additions & 1 deletion
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;
@@ -27,9 +28,12 @@ public function test(): void {
2728
['{DAV:}displayname' => 'Test address book', 'uri' => 'default'],
2829
]);
2930
$propertyMapper = $this->createMock(PropertyMapper::class);
31+
/** @var IAppConfig&MockObject $appConfig */
32+
$appConfig = $this->createMock(IAppConfig::class);
3033

34+
/** @var IL10N&MockObject $l */
3135
$l = $this->createMock(IL10N::class);
32-
$app = new ContactsManager($backEnd, $l, $propertyMapper);
36+
$app = new ContactsManager($backEnd, $l, $propertyMapper, $appConfig);
3337
$app->setupContactsProvider($cm, 'user01', $urlGenerator);
3438
}
3539
}

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)