diff options
author | provokateurin <kate@provokateurin.de> | 2024-12-19 12:22:35 +0100 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2024-12-19 12:46:12 +0100 |
commit | 0030523642fe0513c2c052ebaeb3fc26e8909186 (patch) | |
tree | 59a2fc002fadb4db75df347443ec4e2093757b4a | |
parent | 53aa69018f5e47cd91b430d56511a053a43c5362 (diff) | |
download | nextcloud-server-fix/config/additional-configs.tar.gz nextcloud-server-fix/config/additional-configs.zip |
fix(Config): Prevent setting or deleting config values that are overwritten by additional config filesfix/config/additional-configs
Signed-off-by: provokateurin <kate@provokateurin.de>
-rw-r--r-- | lib/private/Config.php | 12 | ||||
-rw-r--r-- | tests/lib/ConfigTest.php | 22 |
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/private/Config.php b/lib/private/Config.php index a8f0e88d6b7..a605a9201c8 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -124,6 +124,12 @@ class Config { */ protected function set($key, $value) { if (!isset($this->cache[$key]) || $this->cache[$key] !== $value) { + foreach ($this->cachePaths as $file => $keys) { + if ($file !== $this->configFilePath && in_array($key, $keys)) { + throw new HintException('The config key "' . $key . '" is already specified in "' . $file . '" and thus can not be overwritten.'); + } + } + // Add change $this->cache[$key] = $value; return true; @@ -154,6 +160,12 @@ class Config { */ protected function delete($key) { if (isset($this->cache[$key])) { + foreach ($this->cachePaths as $file => $keys) { + if ($file !== $this->configFilePath && in_array($key, $keys)) { + throw new HintException('The config key "' . $key . '" is already specified in "' . $file . '" and thus can not be overwritten.'); + } + } + // Delete key from cache unset($this->cache[$key]); return true; diff --git a/tests/lib/ConfigTest.php b/tests/lib/ConfigTest.php index 1fcd36be8f0..30eb78779be 100644 --- a/tests/lib/ConfigTest.php +++ b/tests/lib/ConfigTest.php @@ -8,6 +8,7 @@ namespace Test; use OC\Config; +use OCP\HintException; class ConfigTest extends TestCase { public const TESTCONTENT = '<?php $CONFIG=array("foo"=>"bar", "beers" => array("Appenzeller", "Guinness", "Kölsch"), "alcohol_free" => false);'; @@ -175,4 +176,25 @@ class ConfigTest extends TestCase { // Cleanup unlink($additionalConfigPath); } + + public function testConfigAdditionalSetDelete(): void { + $additionalConfig = '<?php $CONFIG=array("php53"=>"totallyOutdated");'; + $additionalConfigPath = $this->randomTmpDir . 'additionalConfig.testconfig.php'; + file_put_contents($additionalConfigPath, $additionalConfig); + + $config = new Config($this->randomTmpDir, 'testconfig.php'); + + $this->assertSame('totallyOutdated', $config->getValue('php53', 'bogusValue')); + $this->assertEquals(self::TESTCONTENT, file_get_contents($this->configFile)); + + $this->expectException(HintException::class); + + $this->expectExceptionMessage('The config key "php53" is already specified in "' . $additionalConfigPath . '" and thus can not be overwritten.'); + $config->setValue('php53', 'actuallyNew'); + + $this->expectExceptionMessage('The config key "php53" is specified in "' . $additionalConfigPath . '" and thus can not be deleted.'); + $config->deleteKey('php53'); + + unlink($additionalConfigPath); + } } |