Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 17e418c

Browse filesBrowse files
neskfabpot
authored andcommitted
Verify explicitly that the request IP is a valid IPv4 address
1 parent 56cdaf9 commit 17e418c
Copy full SHA for 17e418c

File tree

2 files changed

+5
-1
lines changed
Filter options

2 files changed

+5
-1
lines changed

‎src/Symfony/Component/HttpFoundation/IpUtils.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/IpUtils.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ public static function checkIp($requestIp, $ips)
6161
*/
6262
public static function checkIp4($requestIp, $ip)
6363
{
64+
if (!filter_var($requestIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
65+
return false;
66+
}
67+
6468
if (false !== strpos($ip, '/')) {
6569
list($address, $netmask) = explode('/', $ip, 2);
6670

6771
if ($netmask === '0') {
68-
// Ensure IP is valid - using ip2long below implicitly validates, but we need to do it manually here
6972
return filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
7073
}
7174

‎src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function testIpv4Provider()
3737
array(true, '1.2.3.4', '0.0.0.0/0'),
3838
array(true, '1.2.3.4', '192.168.1.0/0'),
3939
array(false, '1.2.3.4', '256.256.256/0'), // invalid CIDR notation
40+
array(false, 'an_invalid_ip', '192.168.1.0/24'),
4041
);
4142
}
4243

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.