Skip to content

Commit 3c42906

Browse files
authored
Merge pull request #49039 from nextcloud/jtr/fix-ipv6-zone-ids-link-local
2 parents 452e4be + e885e4f commit 3c42906

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

lib/private/Net/IpAddressClassifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class IpAddressClassifier {
3434
public function isLocalAddress(string $ip): bool {
3535
$parsedIp = Factory::parseAddressString(
3636
$ip,
37-
ParseStringFlag::IPV4_MAYBE_NON_DECIMAL | ParseStringFlag::IPV4ADDRESS_MAYBE_NON_QUAD_DOTTED
37+
ParseStringFlag::IPV4_MAYBE_NON_DECIMAL | ParseStringFlag::IPV4ADDRESS_MAYBE_NON_QUAD_DOTTED | ParseStringFlag::MAY_INCLUDE_ZONEID
3838
);
3939
if ($parsedIp === null) {
4040
/* Not an IP */

lib/private/Security/Ip/Address.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use InvalidArgumentException;
1212
use IPLib\Address\AddressInterface;
1313
use IPLib\Factory;
14+
use IPLib\ParseStringFlag;
1415
use OCP\Security\Ip\IAddress;
1516
use OCP\Security\Ip\IRange;
1617

@@ -21,15 +22,15 @@ class Address implements IAddress {
2122
private readonly AddressInterface $ip;
2223

2324
public function __construct(string $ip) {
24-
$ip = Factory::parseAddressString($ip);
25+
$ip = Factory::parseAddressString($ip, ParseStringFlag::MAY_INCLUDE_ZONEID);
2526
if ($ip === null) {
2627
throw new InvalidArgumentException('Given IP address can’t be parsed');
2728
}
2829
$this->ip = $ip;
2930
}
3031

3132
public static function isValid(string $ip): bool {
32-
return Factory::parseAddressString($ip) !== null;
33+
return Factory::parseAddressString($ip, ParseStringFlag::MAY_INCLUDE_ZONEID) !== null;
3334
}
3435

3536
public function matches(IRange ... $ranges): bool {

lib/private/Security/Ip/Range.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use InvalidArgumentException;
1212
use IPLib\Factory;
13+
use IPLib\ParseStringFlag;
1314
use IPLib\Range\RangeInterface;
1415
use OCP\Security\Ip\IAddress;
1516
use OCP\Security\Ip\IRange;
@@ -30,7 +31,7 @@ public static function isValid(string $range): bool {
3031
}
3132

3233
public function contains(IAddress $address): bool {
33-
return $this->range->contains(Factory::parseAddressString((string)$address));
34+
return $this->range->contains(Factory::parseAddressString((string)$address, ParseStringFlag::MAY_INCLUDE_ZONEID));
3435
}
3536

3637
public function __toString(): string {

tests/lib/Net/IpAddressClassifierTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function localIpAddressData(): array {
4343
return [
4444
['192.168.0.1'],
4545
['fe80::200:5aee:feaa:20a2'],
46+
['fe80::1fc4:15d8:78db:2319%enp4s0'], // v6 zone ID
4647
['0:0:0:0:0:ffff:10.0.0.1'],
4748
['0:0:0:0:0:ffff:127.0.0.0'],
4849
['10.0.0.1'],

tests/lib/Security/Ip/RemoteAddressTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public function dataProvider(): array {
5252
// No configuration
5353
['1.2.3.4', false, true],
5454
['1234:4567:8910::', false, true],
55+
// v6 Zone ID
56+
['fe80::1fc4:15d8:78db:2319%enp4s0', false, true],
5557
// Empty configuration
5658
['1.2.3.4', [], true],
5759
['1234:4567:8910::', [], true],

0 commit comments

Comments
 (0)