diff options
-rw-r--r-- | core/command/config/listconfigs.php | 45 | ||||
-rw-r--r-- | tests/core/command/config/listconfigstest.php | 17 |
2 files changed, 52 insertions, 10 deletions
diff --git a/core/command/config/listconfigs.php b/core/command/config/listconfigs.php index 34a0b7169fd..5796362f2fc 100644 --- a/core/command/config/listconfigs.php +++ b/core/command/config/listconfigs.php @@ -34,15 +34,18 @@ class ListConfigs extends Base { /** @var array */ protected $sensitiveValues = [ - 'dbpassword', - 'dbuser', - 'mail_smtpname', - 'mail_smtppassword', - 'passwordsalt', - 'secret', - 'ldap_agent_password', + 'dbpassword' => true, + 'dbuser' => true, + 'mail_smtpname' => true, + 'mail_smtppassword' => true, + 'passwordsalt' => true, + 'secret' => true, + 'ldap_agent_password' => true, + 'objectstore' => ['arguments' => ['password' => true]], ]; + const SENSITIVE_VALUE = '***REMOVED SENSITIVE VALUE***'; + /** * @var SystemConfig */ protected $systemConfig; @@ -124,11 +127,12 @@ class ListConfigs extends Base { $configs = []; foreach ($keys as $key) { - if ($noSensitiveValues && in_array($key, $this->sensitiveValues)) { - continue; + $value = $this->systemConfig->getValue($key, serialize(null)); + + if ($noSensitiveValues && isset($this->sensitiveValues[$key])) { + $value = $this->removeSensitiveValue($this->sensitiveValues[$key], $value); } - $value = $this->systemConfig->getValue($key, serialize(null)); if ($value !== 'N;') { $configs[$key] = $value; } @@ -136,4 +140,25 @@ class ListConfigs extends Base { return $configs; } + + /** + * @param bool|array $keysToRemove + * @param mixed $value + * @return mixed + */ + protected function removeSensitiveValue($keysToRemove, $value) { + if ($keysToRemove === true) { + return self::SENSITIVE_VALUE; + } + + if (is_array($value)) { + foreach ($keysToRemove as $keyToRemove => $valueToRemove) { + if (isset($value[$keyToRemove])) { + $value[$keyToRemove] = $this->removeSensitiveValue($valueToRemove, $value[$keyToRemove]); + } + } + } + + return $value; + } } diff --git a/tests/core/command/config/listconfigstest.php b/tests/core/command/config/listconfigstest.php index c9913d83f7f..7492701cce3 100644 --- a/tests/core/command/config/listconfigstest.php +++ b/tests/core/command/config/listconfigstest.php @@ -81,6 +81,7 @@ class ListConfigsTest extends TestCase { false, json_encode([ 'system' => [ + 'secret' => ListConfigs::SENSITIVE_VALUE, 'overwrite.cli.url' => 'http://localhost', ], 'apps' => [ @@ -134,10 +135,18 @@ class ListConfigsTest extends TestCase { // config.php [ 'secret', + 'objectstore', 'overwrite.cli.url', ], [ ['secret', 'N;', 'my secret'], + ['objectstore', 'N;', [ + 'class' => 'OC\\Files\\ObjectStore\\Swift', + 'arguments' => [ + 'username' => 'facebook100000123456789', + 'password' => 'Secr3tPaSSWoRdt7', + ], + ]], ['overwrite.cli.url', 'N;', 'http://localhost'], ], // app config @@ -152,6 +161,14 @@ class ListConfigsTest extends TestCase { false, json_encode([ 'system' => [ + 'secret' => ListConfigs::SENSITIVE_VALUE, + 'objectstore' => [ + 'class' => 'OC\\Files\\ObjectStore\\Swift', + 'arguments' => [ + 'username' => 'facebook100000123456789', + 'password' => ListConfigs::SENSITIVE_VALUE, + ], + ], 'overwrite.cli.url' => 'http://localhost', ], ]), |