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:')); } }