diff options
author | Robin Appelman <robin@icewind.nl> | 2020-03-12 19:45:23 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2020-03-12 19:45:23 +0100 |
commit | 0d112d7901983a568f6a803f59f240afd434db61 (patch) | |
tree | f5e89f7532e42ed660efda197693a5745085906a /apps/files_external/lib/Controller/StoragesController.php | |
parent | 24d0fb9fcd8b190b6c16c4608c95785036b1eb31 (diff) | |
download | nextcloud-server-0d112d7901983a568f6a803f59f240afd434db61.tar.gz nextcloud-server-0d112d7901983a568f6a803f59f240afd434db61.zip |
Use placeholder values for password fields in external storage webui
This prevents the password from being sent to the webui.
While an admin will always be able to retrieve the passwords (as they
can do arbitrairy code execution by design) this prevents casual
password snooping
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_external/lib/Controller/StoragesController.php')
-rw-r--r-- | apps/files_external/lib/Controller/StoragesController.php | 78 |
1 files changed, 51 insertions, 27 deletions
diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php index 6b3bb5d6a53..8b1b0cb7a6c 100644 --- a/apps/files_external/lib/Controller/StoragesController.php +++ b/apps/files_external/lib/Controller/StoragesController.php @@ -31,6 +31,7 @@ namespace OCA\Files_External\Controller; use OCA\Files_External\Lib\Auth\AuthMechanism; use OCA\Files_External\Lib\Backend\Backend; +use OCA\Files_External\Lib\DefinitionParameter; use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\NotFoundException; @@ -146,9 +147,9 @@ abstract class StoragesController extends Controller { $mountPoint = $storage->getMountPoint(); if ($mountPoint === '') { return new DataResponse( - array( - 'message' => (string)$this->l10n->t('Invalid mount point') - ), + [ + 'message' => (string)$this->l10n->t('Invalid mount point'), + ], Http::STATUS_UNPROCESSABLE_ENTITY ); } @@ -156,9 +157,9 @@ abstract class StoragesController extends Controller { if ($storage->getBackendOption('objectstore')) { // objectstore must not be sent from client side return new DataResponse( - array( - 'message' => (string)$this->l10n->t('Objectstore forbidden') - ), + [ + 'message' => (string)$this->l10n->t('Objectstore forbidden'), + ], Http::STATUS_UNPROCESSABLE_ENTITY ); } @@ -170,11 +171,11 @@ abstract class StoragesController extends Controller { if ($backend->checkDependencies()) { // invalid backend return new DataResponse( - array( + [ 'message' => (string)$this->l10n->t('Invalid storage backend "%s"', [ - $backend->getIdentifier() - ]) - ), + $backend->getIdentifier(), + ]), + ], Http::STATUS_UNPROCESSABLE_ENTITY ); } @@ -182,22 +183,22 @@ abstract class StoragesController extends Controller { if (!$backend->isVisibleFor($this->service->getVisibilityType())) { // not permitted to use backend return new DataResponse( - array( + [ 'message' => (string)$this->l10n->t('Not permitted to use backend "%s"', [ - $backend->getIdentifier() - ]) - ), + $backend->getIdentifier(), + ]), + ], Http::STATUS_UNPROCESSABLE_ENTITY ); } if (!$authMechanism->isVisibleFor($this->service->getVisibilityType())) { // not permitted to use auth mechanism return new DataResponse( - array( + [ 'message' => (string)$this->l10n->t('Not permitted to use authentication mechanism "%s"', [ - $authMechanism->getIdentifier() - ]) - ), + $authMechanism->getIdentifier(), + ]), + ], Http::STATUS_UNPROCESSABLE_ENTITY ); } @@ -205,9 +206,9 @@ abstract class StoragesController extends Controller { if (!$backend->validateStorage($storage)) { // unsatisfied parameters return new DataResponse( - array( - 'message' => (string)$this->l10n->t('Unsatisfied backend parameters') - ), + [ + 'message' => (string)$this->l10n->t('Unsatisfied backend parameters'), + ], Http::STATUS_UNPROCESSABLE_ENTITY ); } @@ -215,7 +216,7 @@ abstract class StoragesController extends Controller { // unsatisfied parameters return new DataResponse( [ - 'message' => (string)$this->l10n->t('Unsatisfied authentication mechanism parameters') + 'message' => (string)$this->l10n->t('Unsatisfied authentication mechanism parameters'), ], Http::STATUS_UNPROCESSABLE_ENTITY ); @@ -272,7 +273,7 @@ abstract class StoragesController extends Controller { // FIXME: convert storage exceptions to StorageNotAvailableException $storage->setStatus( StorageNotAvailableException::STATUS_ERROR, - get_class($e).': '.$e->getMessage() + get_class($e) . ': ' . $e->getMessage() ); } } @@ -283,7 +284,7 @@ abstract class StoragesController extends Controller { * @return DataResponse */ public function index() { - $storages = $this->service->getStorages(); + $storages = $this->formatStoragesForUI($this->service->getStorages()); return new DataResponse( $storages, @@ -291,6 +292,29 @@ abstract class StoragesController extends Controller { ); } + protected function formatStoragesForUI(array $storages): array { + return array_map(function ($storage) { + return $this->formatStorageForUI($storage); + }, $storages); + } + + protected function formatStorageForUI(StorageConfig $storage): StorageConfig { + /** @var DefinitionParameter[] $parameters */ + $parameters = array_merge($storage->getBackend()->getParameters(), $storage->getAuthMechanism()->getParameters()); + + $options = $storage->getBackendOptions(); + foreach ($options as $key => $value) { + foreach ($parameters as $parameter) { + if ($parameter->getName() === $key && $parameter->getType() === DefinitionParameter::VALUE_PASSWORD) { + $storage->setBackendOption($key, DefinitionParameter::UNMODIFIED_PLACEHOLDER); + break; + } + } + } + + return $storage; + } + /** * Get an external storage entry. * @@ -307,14 +331,14 @@ abstract class StoragesController extends Controller { } catch (NotFoundException $e) { return new DataResponse( [ - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id]), ], Http::STATUS_NOT_FOUND ); } return new DataResponse( - $storage, + $this->formatStorageForUI($storage), Http::STATUS_OK ); } @@ -332,7 +356,7 @@ abstract class StoragesController extends Controller { } catch (NotFoundException $e) { return new DataResponse( [ - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id]), ], Http::STATUS_NOT_FOUND ); |