Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/private/Security/Normalizer/IpAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(
}

/**
* Return the given subnet for an IPv6 address (64 first bits)
* Return the given subnet for an IPv6 address (48 first bits)
*/
private function getIPv6Subnet(string $ip): string {
if ($ip[0] === '[' && $ip[-1] === ']') { // If IP is with brackets, for example [::1]
Expand All @@ -58,9 +58,9 @@ private function getIPv6Subnet(string $ip): string {
}

$binary = \inet_pton($ip);
$mask = inet_pton('FFFF:FFFF:FFFF:FFFF::');
$mask = inet_pton('FFFF:FFFF:FFFF::');

return inet_ntop($binary & $mask).'/64';
return inet_ntop($binary & $mask).'/48';
}

/**
Expand All @@ -85,7 +85,7 @@ private function getEmbeddedIpv4(string $ipv6): ?string {


/**
* Gets either the /32 (IPv4) or the /64 (IPv6) subnet of an IP address
* Gets either the /32 (IPv4) or the /48 (IPv6) subnet of an IP address
*/
public function getSubnet(): string {
if (filter_var($this->ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/Security/Normalizer/IpAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ public function subnetDataProvider() {
'192.168.0.123/32',
],
[
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
'2001:db8:85a3::/64',
'2001:0db8:0000:0000:0000:8a2e:0370:7334',
'2001:db8::/48',
],
[
'2001:db8:3333:4444:5555:6666:7777:8888',
'2001:db8:3333:4444::/64',
'2001:db8:3333::/48',
],
[
'::1234:5678',
'::/64',
'::/48',
],
[
'[::1]',
'::/64',
'::/48',
],
];
}
Expand Down
Loading