Skip to content

Commit 909649f

Browse files
Merge branch '2.7' into 2.8
* 2.7: [travis] Use 7.0 until 7.1 is fixed Verify explicitly that the request IP is a valid IPv4 address
2 parents fc483cf + 386e5e7 commit 909649f

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ matrix:
2828
- php: 5.6
2929
- php: 7.0
3030
env: deps=high
31-
- php: 7.1
31+
- php: 7.0
3232
env: deps=low
3333
fast_finish: true
3434

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines 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

Lines 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)