Skip to content

Commit d0258a1

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 50b6c66 commit d0258a1

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
@@ -26,6 +26,7 @@
2626
namespace OCA\DAV\CardDAV;
2727

2828
use OCP\Contacts\IManager;
29+
use OCP\IAppConfig;
2930
use OCP\IL10N;
3031
use OCP\IURLGenerator;
3132

@@ -36,15 +37,19 @@ class ContactsManager {
3637
/** @var IL10N */
3738
private $l10n;
3839

40+
/** @var IAppConfig */
41+
private $appConfig;
42+
3943
/**
4044
* ContactsManager constructor.
4145
*
4246
* @param CardDavBackend $backend
4347
* @param IL10N $l10n
4448
*/
45-
public function __construct(CardDavBackend $backend, IL10N $l10n) {
49+
public function __construct(CardDavBackend $backend, IL10N $l10n, IAppConfig $appConfig) {
4650
$this->backend = $backend;
4751
$this->l10n = $l10n;
52+
$this->appConfig = $appConfig;
4853
}
4954

5055
/**
@@ -63,6 +68,11 @@ public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlG
6368
* @param IURLGenerator $urlGenerator
6469
*/
6570
public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGenerator) {
71+
$systemAddressBookExposed = $this->appConfig->getValueBool('dav', 'system_addressbook_exposed', true);
72+
if (!$systemAddressBookExposed) {
73+
return;
74+
}
75+
6676
$addressBooks = $this->backend->getAddressBooksForUser("principals/system/system");
6777
$this->register($cm, $addressBooks, $urlGenerator);
6878
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use OCA\DAV\CardDAV\CardDavBackend;
2929
use OCA\DAV\CardDAV\ContactsManager;
3030
use OCP\Contacts\IManager;
31+
use OCP\IAppConfig;
3132
use OCP\IL10N;
3233
use OCP\IURLGenerator;
3334
use Test\TestCase;
@@ -36,16 +37,20 @@ class ContactsManagerTest extends TestCase {
3637
public function test(): void {
3738
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject $cm */
3839
$cm = $this->getMockBuilder(IManager::class)->disableOriginalConstructor()->getMock();
39-
$cm->expects($this->exactly(2))->method('registerAddressBook');
40+
$cm->expects($this->exactly(1))->method('registerAddressBook');
41+
/** @var IURLGenerator&MockObject $urlGenerator */
4042
$urlGenerator = $this->getMockBuilder(IURLGenerator::class)->disableOriginalConstructor()->getMock();
4143
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backEnd */
4244
$backEnd = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
4345
$backEnd->method('getAddressBooksForUser')->willReturn([
4446
['{DAV:}displayname' => 'Test address book', 'uri' => 'default'],
4547
]);
48+
/** @var IAppConfig&MockObject $appConfig */
49+
$appConfig = $this->createMock(IAppConfig::class);
4650

51+
/** @var IL10N&MockObject $l */
4752
$l = $this->createMock(IL10N::class);
48-
$app = new ContactsManager($backEnd, $l);
53+
$app = new ContactsManager($backEnd, $l, $appConfig);
4954
$app->setupContactsProvider($cm, 'user01', $urlGenerator);
5055
}
5156
}

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)