Skip to content

Commit 132fec0

Browse files
committed
feat(ip): use larger IPv6 range by default
Some providers assign `/48` IPv6 blocks instead of `/64` so it sounds safer to use this mask by default. Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
1 parent ae0bb4e commit 132fec0

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

lib/private/Security/Normalizer/IpAddress.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(
2424
}
2525

2626
/**
27-
* Return the given subnet for an IPv6 address (64 first bits)
27+
* Return the given subnet for an IPv6 address (48 first bits)
2828
*/
2929
private function getIPv6Subnet(string $ip): string {
3030
if ($ip[0] === '[' && $ip[-1] === ']') { // If IP is with brackets, for example [::1]
@@ -38,7 +38,7 @@ private function getIPv6Subnet(string $ip): string {
3838
$binary = \inet_pton($ip);
3939
$mask = inet_pton('FFFF:FFFF:FFFF:FFFF::');
4040

41-
return inet_ntop($binary & $mask) . '/64';
41+
return inet_ntop($binary & $mask) . '/48';
4242
}
4343

4444
/**
@@ -63,7 +63,7 @@ private function getEmbeddedIpv4(string $ipv6): ?string {
6363

6464

6565
/**
66-
* Gets either the /32 (IPv4) or the /64 (IPv6) subnet of an IP address
66+
* Gets either the /32 (IPv4) or the /48 (IPv6) subnet of an IP address
6767
*/
6868
public function getSubnet(): string {
6969
if (filter_var($this->ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {

tests/lib/Security/Normalizer/IpAddressTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ public function subnetDataProvider() {
3737
],
3838
[
3939
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
40-
'2001:db8:85a3::/64',
40+
'2001:db8:85a3::/48',
4141
],
4242
[
4343
'2001:db8:3333:4444:5555:6666:7777:8888',
44-
'2001:db8:3333:4444::/64',
44+
'2001:db8:3333:4444::/48',
4545
],
4646
[
4747
'::1234:5678',
48-
'::/64',
48+
'::/48',
4949
],
5050
[
5151
'[::1]',
52-
'::/64',
52+
'::/48',
5353
],
5454
];
5555
}

0 commit comments

Comments
 (0)