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 da25d44

Browse filesBrowse files
committed
bug #24502 [HttpFoundation] never match invalid IP addresses (xabbuh)
This PR was merged into the 2.7 branch. Discussion ---------- [HttpFoundation] never match invalid IP addresses | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24424 | License | MIT | Doc PR | Commits ------- 8ad32f0 never match invalid IP addresses
2 parents aaa5999 + 8ad32f0 commit da25d44
Copy full SHA for da25d44

File tree

2 files changed

+21
-0
lines changed
Filter options

2 files changed

+21
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/IpUtils.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public static function checkIp4($requestIp, $ip)
8787
$netmask = 32;
8888
}
8989

90+
if (false === ip2long($address)) {
91+
return self::$checkedIps[$cacheKey] = false;
92+
}
93+
9094
return self::$checkedIps[$cacheKey] = 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask);
9195
}
9296

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,21 @@ public function testAnIpv6WithOptionDisabledIpv6()
8282

8383
IpUtils::checkIp('2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65');
8484
}
85+
86+
/**
87+
* @dataProvider invalidIpAddressData
88+
*/
89+
public function testInvalidIpAddressesDoNotMatch($requestIp, $proxyIp)
90+
{
91+
$this->assertFalse(IpUtils::checkIp4($requestIp, $proxyIp));
92+
}
93+
94+
public function invalidIpAddressData()
95+
{
96+
return array(
97+
'invalid proxy wildcard' => array('192.168.20.13', '*'),
98+
'invalid proxy missing netmask' => array('192.168.20.13', '0.0.0.0'),
99+
'invalid request IP with invalid proxy wildcard' => array('0.0.0.0', '*'),
100+
);
101+
}
85102
}

0 commit comments

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