Merge pull request #60546 from nextcloud/local-address-nat64

fix: handle NAT64 addresses in isLocalAddress
This commit is contained in:
Daniel 2026-05-20 16:10:25 +02:00 committed by GitHub
commit c0c03fd37f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace OC\Net;
use IPLib\Address\IPv4;
use IPLib\Address\IPv6;
use IPLib\Factory;
use IPLib\ParseStringFlag;
@ -42,7 +43,15 @@ class IpAddressClassifier {
}
/* Replace by normalized form */
if ($parsedIp instanceof IPv6) {
$ip = (string)($parsedIp->toIPv4() ?? $parsedIp);
$ipv4 = $parsedIp->toIPv4();
$ipv6Bytes = $parsedIp->getBytes();
if ($ipv4) {
$ip = (string)$ipv4;
} elseif (array_slice($ipv6Bytes, 0, 4) === [0x00, 0x64, 0xFF, 0x9B]) {
$ip = (string)IPv4::fromBytes(array_slice($ipv6Bytes, -4, 4));
} else {
$ip = (string)$parsedIp;
}
} else {
$ip = (string)$parsedIp;
}

View file

@ -52,6 +52,7 @@ class IpAddressClassifierTest extends TestCase {
['::1'],
['100.100.100.200'],
['192.0.0.1'],
['64:ff9b::a9fe:a9fe'], // NAT64 of 169.254.169.254
];
}