Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpFoundation] Fixed IpUtils::anonymize exception when using IPv6 link-local addresses with RFC4007 scoping #59055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2025
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
10 changes: 10 additions & 0 deletions src/Symfony/Component/HttpFoundation/IpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ public static function checkIp6(string $requestIp, string $ip): bool
*/
public static function anonymize(string $ip): string
{
/**
* If the IP contains a % symbol, then it is a local-link address with scoping according to RFC 4007
* In that case, we only care about the part before the % symbol, as the following functions, can only work with
* the IP address itself. As the scope can leak information (containing interface name), we do not want to
* include it in our anonymized IP data.
*/
if (str_contains($ip, '%')) {
$ip = substr($ip, 0, strpos($ip, '%'));
}

$wrappedIPv6 = false;
if (str_starts_with($ip, '[') && str_ends_with($ip, ']')) {
$wrappedIPv6 = true;
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public static function anonymizedIpData()
['[2a01:198::3]', '[2a01:198::]'],
['::ffff:123.234.235.236', '::ffff:123.234.235.0'], // IPv4-mapped IPv6 addresses
['::123.234.235.236', '::123.234.235.0'], // deprecated IPv4-compatible IPv6 address
['fe80::1fc4:15d8:78db:2319%enp4s0', 'fe80::'], // IPv6 link-local with RFC4007 scoping
];
}

Expand Down
Loading