From 207bb0d62e3405af88dbbf355320ec6d407c724b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 5 Aug 2026 03:33:48 +0000 Subject: [PATCH] fix(installer): reject hostnames with an empty port Hostname inputs like `example.com:` were accepted by both the JS installer validator and the PHP AppDomain validator because an empty port segment was treated as "no port". Reject an explicitly present but empty port, matching the expected installer validation behavior. Closes #13099 Co-authored-by: Chirag Aggarwal --- app/views/install/installer/js/modules/validation.js | 4 +++- src/Appwrite/Platform/Installer/Validator/AppDomain.php | 8 +++++++- .../unit/Platform/Modules/Installer/Runtime/StateTest.php | 5 +++-- .../Modules/Installer/Validator/AppDomainTest.php | 8 +++++--- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/views/install/installer/js/modules/validation.js b/app/views/install/installer/js/modules/validation.js index daa66eb8d6..13d4f9e8a3 100644 --- a/app/views/install/installer/js/modules/validation.js +++ b/app/views/install/installer/js/modules/validation.js @@ -69,12 +69,14 @@ const parts = trimmed.split(':'); if (parts.length > 2) return false; if (parts.length === 2) { + // Trailing colon with no digits is an explicit but empty port. + if (!parts[1]) return false; host = parts[0]; port = parts[1]; } } - if (port !== null && port !== '' && !isValidPort(port)) { + if (port !== null && !isValidPort(port)) { return false; } diff --git a/src/Appwrite/Platform/Installer/Validator/AppDomain.php b/src/Appwrite/Platform/Installer/Validator/AppDomain.php index 5d18b5214a..8a052ccba1 100644 --- a/src/Appwrite/Platform/Installer/Validator/AppDomain.php +++ b/src/Appwrite/Platform/Installer/Validator/AppDomain.php @@ -59,7 +59,13 @@ class AppDomain extends Validator } } - if ($port !== null && $port !== '') { + // A trailing colon with no digits (e.g. example.com:) is invalid — + // the port was explicitly attempted but left empty. + if ($port !== null) { + if ($port === '') { + return false; + } + $portInt = (int) $port; if ((string) $portInt !== $port || $portInt < 1 || $portInt > 65535) { return false; diff --git a/tests/unit/Platform/Modules/Installer/Runtime/StateTest.php b/tests/unit/Platform/Modules/Installer/Runtime/StateTest.php index a76e6c38d9..8edc5fedcb 100644 --- a/tests/unit/Platform/Modules/Installer/Runtime/StateTest.php +++ b/tests/unit/Platform/Modules/Installer/Runtime/StateTest.php @@ -536,8 +536,9 @@ final class StateTest extends TestCase public function testIsValidAppDomainInputWithEmptyPort(): void { - // "host:" splits to ['host', ''] - empty port with null check - $this->assertTrue($this->state->isValidAppDomainInput('localhost:')); + // Trailing colon with no digits is an explicit but empty port. + $this->assertFalse($this->state->isValidAppDomainInput('localhost:')); + $this->assertFalse($this->state->isValidAppDomainInput('example.com:')); } public function testIsValidAppDomainInputWithIpv4Address(): void diff --git a/tests/unit/Platform/Modules/Installer/Validator/AppDomainTest.php b/tests/unit/Platform/Modules/Installer/Validator/AppDomainTest.php index 14c57f9ce9..b476223b39 100644 --- a/tests/unit/Platform/Modules/Installer/Validator/AppDomainTest.php +++ b/tests/unit/Platform/Modules/Installer/Validator/AppDomainTest.php @@ -161,9 +161,11 @@ final class AppDomainTest extends TestCase $this->assertTrue($this->validator->isValid(' example.com ')); } - public function testAcceptsEmptyPortSegment(): void + public function testRejectsEmptyPortSegment(): void { - // 'localhost:' splits into host='localhost', port='' — empty port is skipped - $this->assertTrue($this->validator->isValid('localhost:')); + // Trailing colon with no digits is an explicit but empty port. + $this->assertFalse($this->validator->isValid('localhost:')); + $this->assertFalse($this->validator->isValid('example.com:')); + $this->assertFalse($this->validator->isValid('127.0.0.1:')); } }