mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
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 <chiragaggarwal5k@gmail.com>
This commit is contained in:
1 parent
849f17ccbf
commit
207bb0d62e
4 files changed
+18
-7
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:'));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user