Skip to content

Fix #61700: FILTER_FLAG_IPV6/FILTER_FLAG_NO_PRIV|RES_RANGE failing #7476

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

Closed
wants to merge 8 commits into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Sep 7, 2021

It makes no sense to compare IPv6 address ranges as strings; there are
too many different representation possibilities. Instead, we change
_php_filter_validate_ipv6() so that it can calculate the IP address
as integer array. We do not rely on inet_pton() which may not be
available everywhere, at least IPv6 support may not, but rather parse
the IP address manually. Finally, we compare the integers.

Note that this patch does not fix what we consider as reserved and
private, respectively, but merely tries to keep what we had so far.


Regarding filter_var('::ffff:192.168.1.1', FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE): it is not necessarily clear what this should return. In the bug ticket, requinix argues that it likely should fail, but it currently does not.

It makes no sense to compare IPv6 address ranges as strings; there are
too many different representation possibilities.  Instead, we change
`_php_filter_validate_ipv6()` so that it can calculate the IP address
as integer array.  We do not rely on `inet_pton()` which may not be
available everywhere, at least IPv6 support may not, but rather parse
the IP address manually.  Finally, we compare the integers.

Note that this patch does not fix what we consider as reserved and
private, respectively, but merely tries to keep what we had so far.
@cmb69 cmb69 added the Bug label Sep 7, 2021
@cmb69
Copy link
Member Author

cmb69 commented Sep 14, 2021

In my opinion, fixing this bug is important, but I'm not sure about the details, so I'd like some review.

cmb69 and others added 3 commits September 20, 2021 12:19
Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
We also need to do this for `blocks == 8`, to replace the single `-1`
with `0`.  In this case the first `for` loop is unnecessary, but it
doesn't really hurt to run it.
@cmb69 cmb69 closed this in 288c25f Sep 20, 2021
@cmb69 cmb69 deleted the cmb/61700 branch September 20, 2021 15:48
cmb69 pushed a commit that referenced this pull request Dec 19, 2021
`2001:10::/28` is a reserved IPv6 range. But there's a typo in GH-7476,
which caused IPv6 address like `240b:0010::1` will be filtered by the
flag `FILTER_FLAG_NO_RES_RANGE`.

http://www.faqs.org/rfcs/rfc6890.html

Closes GH-7790.
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.

2 participants