Skip to content

Commit 7d03169

Browse files
committed
fix(config): Don't print sensitive config when setting them
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent aed4fd0 commit 7d03169

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

core/Command/Config/System/SetConfig.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OC\Core\Command\Config\System;
1010

1111
use OC\SystemConfig;
12+
use OCP\IConfig;
1213
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
1314
use Symfony\Component\Console\Input\InputArgument;
1415
use Symfony\Component\Console\Input\InputInterface;
@@ -80,10 +81,41 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8081
$this->systemConfig->setValue($configName, $configValue['value']);
8182
}
8283

83-
$output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' set to ' . $configValue['readable-value'] . '</info>');
84+
$readableValue = $this->getReadableValue($configNames, $configValue);
85+
86+
$output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' set to ' . $readableValue . '</info>');
8487
return 0;
8588
}
8689

90+
/**
91+
* Builds the value to print for the console output, masking it (or the
92+
* sensitive parts of it) in case the config key is considered sensitive
93+
* by SystemConfig.
94+
*
95+
* @param string[] $configNames
96+
* @param array{value: mixed, readable-value: string} $configValue
97+
*/
98+
protected function getReadableValue(array $configNames, array $configValue): string {
99+
$filteredValue = $this->systemConfig->getFilteredValue($configNames[0]);
100+
foreach (array_slice($configNames, 1) as $key) {
101+
if (!is_array($filteredValue) || !array_key_exists($key, $filteredValue)) {
102+
// Nothing got filtered along this path
103+
return $configValue['readable-value'];
104+
}
105+
$filteredValue = $filteredValue[$key];
106+
}
107+
108+
if ($filteredValue === $configValue['value']) {
109+
return $configValue['readable-value'];
110+
}
111+
112+
if ($filteredValue === IConfig::SENSITIVE_VALUE) {
113+
return IConfig::SENSITIVE_VALUE;
114+
}
115+
116+
return 'array ' . json_encode($filteredValue);
117+
}
118+
87119
/**
88120
* @param array $configNames
89121
* @param mixed $existingValues

0 commit comments

Comments
 (0)