Merge pull request #49039 from nextcloud/jtr/fix-ipv6-zone-ids-link-local

pull/49090/head
John Molakvoæ 2024-11-06 09:17:52 +07:00 committed by GitHub
commit 3c4290631b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 4 deletions

@ -34,7 +34,7 @@ class IpAddressClassifier {
public function isLocalAddress(string $ip): bool {
$parsedIp = Factory::parseAddressString(
$ip,
ParseStringFlag::IPV4_MAYBE_NON_DECIMAL | ParseStringFlag::IPV4ADDRESS_MAYBE_NON_QUAD_DOTTED
ParseStringFlag::IPV4_MAYBE_NON_DECIMAL | ParseStringFlag::IPV4ADDRESS_MAYBE_NON_QUAD_DOTTED | ParseStringFlag::MAY_INCLUDE_ZONEID
);
if ($parsedIp === null) {
/* Not an IP */

@ -11,6 +11,7 @@ namespace OC\Security\Ip;
use InvalidArgumentException;
use IPLib\Address\AddressInterface;
use IPLib\Factory;
use IPLib\ParseStringFlag;
use OCP\Security\Ip\IAddress;
use OCP\Security\Ip\IRange;
@ -21,7 +22,7 @@ class Address implements IAddress {
private readonly AddressInterface $ip;
public function __construct(string $ip) {
$ip = Factory::parseAddressString($ip);
$ip = Factory::parseAddressString($ip, ParseStringFlag::MAY_INCLUDE_ZONEID);
if ($ip === null) {
throw new InvalidArgumentException('Given IP address cant be parsed');
}
@ -29,7 +30,7 @@ class Address implements IAddress {
}
public static function isValid(string $ip): bool {
return Factory::parseAddressString($ip) !== null;
return Factory::parseAddressString($ip, ParseStringFlag::MAY_INCLUDE_ZONEID) !== null;
}
public function matches(IRange ... $ranges): bool {

@ -10,6 +10,7 @@ namespace OC\Security\Ip;
use InvalidArgumentException;
use IPLib\Factory;
use IPLib\ParseStringFlag;
use IPLib\Range\RangeInterface;
use OCP\Security\Ip\IAddress;
use OCP\Security\Ip\IRange;
@ -30,7 +31,7 @@ class Range implements IRange {
}
public function contains(IAddress $address): bool {
return $this->range->contains(Factory::parseAddressString((string)$address));
return $this->range->contains(Factory::parseAddressString((string)$address, ParseStringFlag::MAY_INCLUDE_ZONEID));
}
public function __toString(): string {

@ -43,6 +43,7 @@ class IpAddressClassifierTest extends TestCase {
return [
['192.168.0.1'],
['fe80::200:5aee:feaa:20a2'],
['fe80::1fc4:15d8:78db:2319%enp4s0'], // v6 zone ID
['0:0:0:0:0:ffff:10.0.0.1'],
['0:0:0:0:0:ffff:127.0.0.0'],
['10.0.0.1'],

@ -52,6 +52,8 @@ class RemoteAddressTest extends \Test\TestCase {
// No configuration
['1.2.3.4', false, true],
['1234:4567:8910::', false, true],
// v6 Zone ID
['fe80::1fc4:15d8:78db:2319%enp4s0', false, true],
// Empty configuration
['1.2.3.4', [], true],
['1234:4567:8910::', [], true],