Skip to content

Commit ca56338

Browse files
icewind1991backportbot[bot]
authored andcommitted
fix: strip trailing dots from hostnames and ips before validation
fix: strip trailing dots from hostnames and ips before validation Signed-off-by: Robin Appelman <robin@icewind.nl> [skip ci]
1 parent b908f6c commit ca56338

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
@@ -35,6 +35,8 @@ public function isValid(string $host): bool {
3535
return true;
3636
}
3737

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

tests/lib/Net/HostnameClassifierTest.php

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

@@ -48,6 +49,7 @@ public function publicHostnamesData(): array {
4849
['example.org'],
4950
['host.domain'],
5051
['cloud.domain.tld'],
52+
['cloud.domain.tld.'],
5153
];
5254
}
5355

0 commit comments

Comments
 (0)