Skip to content

Commit 3a67080

Browse files
committed
fix(appconfig): Make sure sensitive values stay sensitive
Signed-off-by: Joas Schilling <[email protected]>
1 parent 24607a3 commit 3a67080

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

lib/private/AppConfig.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,13 @@ private function setTypedValue(
754754
* no update if key is already known with set lazy status, or value is
755755
* different, or sensitivity switched from false to true.
756756
*/
757-
if (!$sensitive
758-
&& $this->hasKey($app, $key, $lazy)
757+
if ($this->hasKey($app, $key, $lazy)
759758
&& $value === $this->getTypedValue($app, $key, $value, $lazy, $type)
760-
&& !$this->isSensitive($app, $key, $lazy)) {
759+
&& (!$sensitive || $this->isSensitive($app, $key, $lazy))) {
761760
return false;
762761
}
763762

764-
if ($sensitive) {
763+
if ($sensitive || ($this->hasKey($app, $key, $lazy) && $this->isSensitive($app, $key, $lazy))) {
765764
$value = self::ENCRYPTION_PREFIX . $this->crypto->encrypt($value);
766765
}
767766

@@ -812,7 +811,7 @@ private function setTypedValue(
812811

813812
// we fix $type if the stored value, or the new value as it might be changed, is set as sensitive
814813
if ($sensitive || $this->isTyped(self::VALUE_SENSITIVE, $currType)) {
815-
$type = $type | self::VALUE_SENSITIVE;
814+
$type |= self::VALUE_SENSITIVE;
816815
}
817816

818817
if ($lazy !== $this->isLazy($app, $key)) {

tests/lib/AppConfigTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,20 +877,29 @@ public function testSetNonSensitiveValueStringAsSensitive(): void {
877877
$config->setValueString('feed', 'string', 'value-1', sensitive: false);
878878
$config->setValueString('feed', 'string', 'value-1', sensitive: true);
879879
$this->assertSame(true, $config->isSensitive('feed', 'string'));
880+
881+
$this->assertConfigValueNotEquals('feed', 'string', 'value-1');
882+
$this->assertConfigValueNotEquals('feed', 'string', 'value-2');
880883
}
881884

882885
public function testSetSensitiveValueStringAsNonSensitiveStaysSensitive(): void {
883886
$config = $this->generateAppConfig();
884887
$config->setValueString('feed', 'string', 'value-1', sensitive: true);
885888
$config->setValueString('feed', 'string', 'value-2', sensitive: false);
886889
$this->assertSame(true, $config->isSensitive('feed', 'string'));
890+
891+
$this->assertConfigValueNotEquals('feed', 'string', 'value-1');
892+
$this->assertConfigValueNotEquals('feed', 'string', 'value-2');
887893
}
888894

889895
public function testSetSensitiveValueStringAsNonSensitiveAreStillUpdated(): void {
890896
$config = $this->generateAppConfig();
891897
$config->setValueString('feed', 'string', 'value-1', sensitive: true);
892898
$config->setValueString('feed', 'string', 'value-2', sensitive: false);
893899
$this->assertSame('value-2', $config->getValueString('feed', 'string', ''));
900+
901+
$this->assertConfigValueNotEquals('feed', 'string', 'value-1');
902+
$this->assertConfigValueNotEquals('feed', 'string', 'value-2');
894903
}
895904

896905
public function testSetLazyValueInt(): void {

0 commit comments

Comments
 (0)