Skip to content

Commit 256c4c3

Browse files
committed
fix: strip trailing dots from hostnames and ips before validation
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 5dc786b commit 256c4c3

4 files changed

Lines changed: 6 additions & 0 deletions

File tree

lib/private/Net/HostnameClassifier.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class HostnameClassifier {
3838
* IP addresses are not considered local. Use the IpAddressClassifier for those.
3939
*/
4040
public function isLocalHostname(string $hostname): bool {
41+
$hostname = rtrim($hostname, '.');
4142
// Disallow local network top-level domains from RFC 6762
4243
$topLevelDomain = substr((strrchr($hostname, '.') ?: ''), 1);
4344
if (in_array($topLevelDomain, self::LOCAL_TOPLEVEL_DOMAINS)) {

lib/private/Net/IpAddressClassifier.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function getMappedIpv4(IPv6 $ip): ?IPv4 {
7070
* Hostnames are not considered local. Use the HostnameClassifier for those.
7171
*/
7272
public function isLocalAddress(string $ip): bool {
73+
$ip = rtrim($ip, '.');
7374
$parsedIp = Factory::parseAddressString(
7475
$ip,
7576
ParseStringFlag::IPV4_MAYBE_NON_DECIMAL | ParseStringFlag::IPV4ADDRESS_MAYBE_NON_QUAD_DOTTED | ParseStringFlag::MAY_INCLUDE_ZONEID

lib/private/Security/RemoteHostValidator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public function isValid(string $host): bool {
3636
return true;
3737
}
3838

39+
$host = rtrim($host, '.');
40+
3941
$host = idn_to_utf8(strtolower(urldecode($host)));
4042
if ($host === false) {
4143
return false;

tests/lib/Net/HostnameClassifierTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static function localHostnamesData(): array {
3030
['another-host.local'],
3131
['service.localhost'],
3232
['randomdomain.internal'],
33+
['another-host.local.'],
3334
];
3435
}
3536

@@ -47,6 +48,7 @@ public static function publicHostnamesData(): array {
4748
['example.org'],
4849
['host.domain'],
4950
['cloud.domain.tld'],
51+
['cloud.domain.tld.'],
5052
];
5153
}
5254

0 commit comments

Comments
 (0)