Skip to content

[HttpFoundation] Add optional $v4Bytes and $v6Bytes parameters to IpUtils::anonymize() #58038

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
Aug 22, 2024

Conversation

alexandre-daubois
Copy link
Member

@alexandre-daubois alexandre-daubois commented Aug 20, 2024

Q A
Branch? 7.2
Bug fix? on
New feature? yes
Deprecations? no
Issues Fix #50778
License MIT
Doc PR symfony/symfony-docs#20138

This PR answers to the need of more anonymization of IP addresses. This adds 2 new parameters to the IpUtils::anonymize() that you can use this way:

$ipv4 = '123.234.235.236';
$anonymousIpv4 = IpUtils::anonymize($ipv4, v4Bytes: 3);
// $anonymousIpv4 = '123.0.0.0'

$ipv6 = '2a01:198:603:10:396e:4789:8e99:890f';
$anonymousIpv6 = IpUtils::anonymize($ipv6, v6Bytes: 10);
// $anonymousIpv6 = '2a01:198:603::'

@alexandre-daubois alexandre-daubois changed the title [HttpFoundation] Add optional $bytesToAnonymize argument to IpUtils::anonymize() [HttpFoundation] Add optional $anonymizedBytesForV4 and $anonymizedBytesForV6 arguments to IpUtils::anonymize() Aug 20, 2024
@alexandre-daubois alexandre-daubois force-pushed the ano-ip-bytes branch 3 times, most recently from 72c535a to 86313bb Compare August 20, 2024 12:31
@alexandre-daubois alexandre-daubois changed the title [HttpFoundation] Add optional $anonymizedBytesForV4 and $anonymizedBytesForV6 arguments to IpUtils::anonymize() [HttpFoundation] Add optional $v4Bytes and $v6Bytes arguments to IpUtils::anonymize() Aug 21, 2024
@OskarStark OskarStark changed the title [HttpFoundation] Add optional $v4Bytes and $v6Bytes arguments to IpUtils::anonymize() [HttpFoundation] Add optional $v4Bytes and $v6Bytes parameters to IpUtils::anonymize() Aug 21, 2024
* Removes the last byte for v4 and the last 8 bytes for v6 IPs
* Removes the last bytes of IPv4 and IPv6 addresses (1 byte for IPv4 and 8 bytes for IPv6 by default).
*
* @param int<0, 4> $v4Bytes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param int<0, 4> $v4Bytes
* @param int<0, 4> $v4Bytes

@fabpot
Copy link
Member

fabpot commented Aug 22, 2024

Thank you @alexandre-daubois.

@fabpot fabpot merged commit beca579 into symfony:7.2 Aug 22, 2024
6 of 10 checks passed
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Aug 26, 2024
…ze()` (alexandre-daubois)

This PR was merged into the 7.2 branch.

Discussion
----------

[HttpFoundation] Add new parameters to `IpUtils::anonymize()`

Related to symfony/symfony#58038

Commits
-------

84da11c [HttpFoundation] Add new parameters to `IpUtils::anonymize()`
@fabpot fabpot mentioned this pull request Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make IpUtils::anonymize configurable
5 participants