Skip to content

Commit e1be59b

Browse files
authored
Merge pull request #449 from nextcloud/backport/447/stable30
[stable30] (fix): do not expose haproxy password to UI
2 parents 8877251 + d71d5eb commit e1be59b

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

lib/Controller/DaemonConfigController.php

+44-1
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,37 @@ public function registerDaemonConfig(array $daemonConfigParams, bool $defaultDae
5959
#[PasswordConfirmationRequired]
6060
public function updateDaemonConfig(string $name, array $daemonConfigParams): Response {
6161
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($name);
62+
63+
// Safely check if "haproxy_password" exists before accessing it
64+
$haproxyPassword = $daemonConfigParams['deploy_config']['haproxy_password'] ?? null;
65+
66+
// Restore the original password if "dummySecret123" is provided
67+
if ($haproxyPassword === 'dummySecret123') {
68+
$daemonConfigParams['deploy_config']['haproxy_password'] = $daemonConfig->getDeployConfig()['haproxy_password'] ?? "";
69+
}
70+
71+
// Create and update DaemonConfig instance
6272
$updatedDaemonConfig = new DaemonConfig($daemonConfigParams);
6373
$updatedDaemonConfig->setId($daemonConfig->getId());
6474
$updatedDaemonConfig = $this->daemonConfigService->updateDaemonConfig($updatedDaemonConfig);
75+
76+
// Check if update was successful before proceeding
77+
if ($updatedDaemonConfig === null) {
78+
return new JSONResponse([
79+
'success' => false,
80+
'daemonConfig' => null,
81+
]);
82+
}
83+
84+
// Mask the password with "dummySecret123" if it is set
85+
$updatedDeployConfig = $updatedDaemonConfig->getDeployConfig();
86+
if (!empty($updatedDeployConfig['haproxy_password'] ?? null)) {
87+
$updatedDeployConfig['haproxy_password'] = 'dummySecret123';
88+
$updatedDaemonConfig->setDeployConfig($updatedDeployConfig);
89+
}
90+
6591
return new JSONResponse([
66-
'success' => $updatedDaemonConfig !== null,
92+
'success' => true,
6793
'daemonConfig' => $updatedDaemonConfig,
6894
]);
6995
}
@@ -98,6 +124,23 @@ public function verifyDaemonConnection(string $name): Response {
98124
}
99125

100126
public function checkDaemonConnection(array $daemonParams): Response {
127+
// Safely check if "haproxy_password" exists before accessing it
128+
// note: UI passes here 'deploy_config' instead of 'deployConfig'
129+
$haproxyPassword = $daemonParams['deploy_config']['haproxy_password'] ?? null;
130+
131+
if ($haproxyPassword === 'dummySecret123') {
132+
// If the secret is "dummySecret123" we check if such record is present in DB
133+
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($daemonParams['name']);
134+
if ($daemonConfig !== null) {
135+
$haproxyPasswordDB = $daemonConfig->getDeployConfig()['haproxy_password'] ?? "";
136+
if ($haproxyPasswordDB) {
137+
// if there is a record in the DB and there is a password,
138+
// then we request it from the DB instead of the “masked” one
139+
$daemonParams['deploy_config']['haproxy_password'] = $haproxyPasswordDB;
140+
}
141+
}
142+
}
143+
101144
$daemonConfig = new DaemonConfig([
102145
'name' => $daemonParams['name'],
103146
'display_name' => $daemonParams['display_name'],

lib/Service/DaemonConfigService.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,18 @@ public function getDaemonConfigsWithAppsCount(): array {
8181
$carry[$exApp->getDaemonConfigName()] += 1;
8282
return $carry;
8383
}, []);
84+
8485
return array_map(function (DaemonConfig $daemonConfig) use ($daemonsExAppsCount) {
86+
$serializedConfig = $daemonConfig->jsonSerialize();
87+
88+
// Check if "haproxy_password" exists in "deployConfig" and mask it
89+
if (!empty($serializedConfig['deploy_config']['haproxy_password'])) {
90+
$serializedConfig['deploy_config']['haproxy_password'] = 'dummySecret123';
91+
}
92+
8593
return [
86-
...$daemonConfig->jsonSerialize(),
87-
'exAppsCount' => isset($daemonsExAppsCount[$daemonConfig->getName()]) ? $daemonsExAppsCount[$daemonConfig->getName()] : 0,
94+
...$serializedConfig,
95+
'exAppsCount' => $daemonsExAppsCount[$daemonConfig->getName()] ?? 0,
8896
];
8997
}, $this->getRegisteredDaemonConfigs());
9098
}

0 commit comments

Comments
 (0)