Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Verify explicitly that the request IP is a valid IPv4 address#19666
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Closed
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Member
nicolas-grekas commentedAug 19, 2016
could you add a test case please? |
Test added for thec2b4525 commit
ContributorAuthor
nesk commentedAug 19, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Done, added a new assertion checking if this line returns IpUtils::checkIp('an_invalid_ip','192.168.1.0/24'); |
Member
fabpot commentedAug 19, 2016
Thank you@nesk. |
fabpot added a commit that referenced this pull requestAug 19, 2016
…ess (nesk)This PR was squashed before being merged into the 2.7 branch (closes#19666).Discussion----------Verify explicitly that the request IP is a valid IPv4 address| Q | A| ------------- | ---| Branch? | 2.7| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -Take the following base code (the array is based on [CloudFlare IP Ranges](https://www.cloudflare.com/ips/)):```phpuse Symfony\Component\HttpFoundation\IpUtils;$ips = [ "103.21.244.0/22", "103.22.200.0/22", "103.31.4.0/22", "104.16.0.0/12", "108.162.192.0/18", "131.0.72.0/22", "141.101.64.0/18", "162.158.0.0/15", "172.64.0.0/13", "173.245.48.0/20", "188.114.96.0/20", "190.93.240.0/20", "197.234.240.0/22", "198.41.128.0/17", "199.27.128.0/21", "2400:cb00::/32", "2405:8100::/32", "2405:b500::/32", "2606:4700::/32", "2803:f800::/32", "2c0f:f248::/32", "2a06:98c0::/29",];```Before this PR, the following code would have returned `true` instead of the expected `false` value:```phpIpUtils::checkIp('blablabla', $ips);```This due to the `ip2long` function returning `false` for an invalid IP address, thus returning `"00000000000000000000000000000000"` with the following code:```phpsprintf('%032b', ip2long('blablabla'));```To fix this I simply check if the `$requestIp` variable contains a valid IP address.Commits-------17e418c Verify explicitly that the request IP is a valid IPv4 address
This was referencedSep 2, 2016
Merged
Merged
Merged
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Take the following base code (the array is based onCloudFlare IP Ranges):
Before this PR, the following code would have returned
trueinstead of the expectedfalsevalue:This due to the
ip2longfunction returningfalsefor an invalid IP address, thus returning"00000000000000000000000000000000"with the following code:To fix this I simply check if the
$requestIpvariable contains a valid IP address.