Skip to content

Commit 2de5062

Browse files
authored
Merge pull request #1666 from solracsf/fix/empty-app-id-whitelist
fix(whitelisting): Never treat the empty app id as whitelisted
2 parents 5805f9b + 0c2856a commit 2de5062

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

lib/AppWhitelist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AppWhitelist {
2828

2929
private readonly int $baseUrlLength;
3030

31-
public const WHITELIST_ALWAYS = ',core,theming,settings,avatar,files,heartbeat,dav,guests,impersonate,accessibility,terms_of_service,dashboard,weather_status,user_status,apporder,twofactor_totp,twofactor_webauthn,twofactor_backupcodes,twofactor_nextcloud_notification';
31+
public const WHITELIST_ALWAYS = 'core,theming,settings,avatar,files,heartbeat,dav,guests,impersonate,accessibility,terms_of_service,dashboard,weather_status,user_status,apporder,twofactor_totp,twofactor_webauthn,twofactor_backupcodes,twofactor_nextcloud_notification';
3232

3333
public const DEFAULT_WHITELIST = 'files_trashbin,files_versions,files_sharing,files_texteditor,text,activity,firstrunwizard,photos,notifications,dashboard,user_status,weather_status';
3434

lib/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function setUseWhitelist(bool $use): void {
104104
* @return list<string>
105105
*/
106106
public function getAppWhitelist(): array {
107-
return explode(',', $this->appConfig->getAppValueString(ConfigLexicon::WHITE_LIST));
107+
return array_values(array_filter(explode(',', $this->appConfig->getAppValueString(ConfigLexicon::WHITE_LIST)), static fn (string $app): bool => $app !== ''));
108108
}
109109

110110
public function setAppWhitelist(array $whitelist): void {

tests/unit/AppWhitelistTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,15 @@ public function testIsUrlAllowedNoWhitelist(): void {
8282
$this->assertTrue($this->appWhitelist->isUrlAllowed($user, '/apps/news/...'));
8383
$this->assertTrue($this->appWhitelist->isUrlAllowed($user, '/apps/foo/...'));
8484
}
85+
86+
/**
87+
* getRequestedApp() returns an empty string for urls that carry no
88+
* resolvable app id, so it must never be treated as whitelisted.
89+
*/
90+
public function testEmptyAppIdIsNotWhitelisted(): void {
91+
$this->config->method('getAppWhitelist')
92+
->willReturn(['foo', 'bar']);
93+
94+
$this->assertFalse($this->appWhitelist->isAppWhitelisted(''));
95+
}
8596
}

tests/unit/ConfigTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ public function testGetAppWhitelist(): void {
123123
$this->assertEquals(['app1', 'app2', 'app3'], $this->guestConfig->getAppWhitelist());
124124
}
125125

126+
public function testGetAppWhitelistEmpty(): void {
127+
$this->appConfig->method('getAppValueString')
128+
->with('whitelist')
129+
->willReturn('');
130+
131+
// explode() on an empty string yields a single empty entry, which
132+
// would both whitelist the empty app id and show up as a blank entry
133+
// in the admin settings.
134+
$this->assertEquals([], $this->guestConfig->getAppWhitelist());
135+
}
136+
126137
public function testSetAppWhitelistArray(): void {
127138
$this->appConfig->expects($this->once())
128139
->method('setAppValueString')

0 commit comments

Comments
 (0)