diff --git a/app/views/install/installer/js/steps.js b/app/views/install/installer/js/steps.js index 057496f2e5..66b95e31eb 100644 --- a/app/views/install/installer/js/steps.js +++ b/app/views/install/installer/js/steps.js @@ -446,10 +446,11 @@ valid = false; } - if (!password || !password.value.trim()) { + const passwordValue = password?.value ?? ''; + if (!password || !/\S/.test(passwordValue)) { setFieldError?.(password, 'Please enter a password'); valid = false; - } else if (!isValidPassword?.(password.value.trim())) { + } else if (!isValidPassword?.(passwordValue)) { setFieldError?.(password, 'Password must be at least 8 characters'); valid = false; } diff --git a/src/Appwrite/Platform/Installer/HttpHandler.php b/src/Appwrite/Platform/Installer/HttpHandler.php index e4c1b0995f..9e663e227c 100644 --- a/src/Appwrite/Platform/Installer/HttpHandler.php +++ b/src/Appwrite/Platform/Installer/HttpHandler.php @@ -298,7 +298,7 @@ class HttpHandler $input['emailCertificates'] = $emailCertificates; $opensslKey = trim((string) ($input['opensslKey'] ?? '')); - if ($opensslKey === '' || strlen($opensslKey) > 64) { + if (!$this->state->isValidSecretKey($opensslKey)) { $this->respondBadRequest('Secret API key must be 1-64 characters', $wantsStream); } $input['opensslKey'] = $opensslKey; @@ -308,7 +308,7 @@ class HttpHandler if (!$this->config->isUpgrade()) { $accountName = trim((string) ($input['accountName'] ?? '')); - if ($accountName === '') { + if (!$this->state->isValidAccountName($accountName)) { $this->respondBadRequest('Please enter a name', $wantsStream, Server::STEP_ACCOUNT_SETUP); } @@ -318,7 +318,7 @@ class HttpHandler } $accountPassword = (string) ($input['accountPassword'] ?? ''); - if (!preg_match('/\\S/', $accountPassword) || !$this->state->isValidPassword($accountPassword)) { + if (!$this->state->isValidPassword($accountPassword)) { $this->respondBadRequest('Password must be at least 8 characters', $wantsStream, Server::STEP_ACCOUNT_SETUP); } diff --git a/src/Appwrite/Platform/Installer/Runtime/State.php b/src/Appwrite/Platform/Installer/Runtime/State.php index 94b0009a5a..068bc9ca2e 100644 --- a/src/Appwrite/Platform/Installer/Runtime/State.php +++ b/src/Appwrite/Platform/Installer/Runtime/State.php @@ -143,6 +143,16 @@ class State return strlen($value) >= 8 && preg_match('/\S/', $value) === 1; } + public function isValidSecretKey(string $value): bool + { + return $value !== '' && strlen($value) <= 64; + } + + public function isValidAccountName(string $value): bool + { + return trim($value) !== ''; + } + public function isValidAppDomainInput(string $value): bool { $value = trim($value);