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 5ac1693

Browse filesBrowse files
committed
bug #48421 [HttpFoundation] IPv4-mapped IPv6 addresses incorrectly rejected (bonroyage)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [HttpFoundation] IPv4-mapped IPv6 addresses incorrectly rejected | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #48420 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT I've based it on 4.4 because that's where #48050 was merged into, but I guess I'm 1 day too late with a fix for that version Commits ------- 2170d3c [HttpFoundation] IPv4-mapped IPv6 addresses incorrectly rejected
2 parents e807503 + 2170d3c commit 5ac1693
Copy full SHA for 5ac1693

File tree

Expand file treeCollapse file tree

2 files changed

+9
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/IpUtils.php
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,17 @@ public static function checkIp6(?string $requestIp, string $ip)
136136
}
137137

138138
// Check to see if we were given a IP4 $requestIp or $ip by mistake
139-
if (str_contains($requestIp, '.') || str_contains($ip, '.')) {
140-
return self::$checkedIps[$cacheKey] = false;
141-
}
142-
143139
if (!filter_var($requestIp, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
144140
return self::$checkedIps[$cacheKey] = false;
145141
}
146142

147143
if (str_contains($ip, '/')) {
148144
[$address, $netmask] = explode('/', $ip, 2);
149145

146+
if (!filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
147+
return self::$checkedIps[$cacheKey] = false;
148+
}
149+
150150
if ('0' === $netmask) {
151151
return (bool) unpack('n*', @inet_pton($address));
152152
}
@@ -155,6 +155,10 @@ public static function checkIp6(?string $requestIp, string $ip)
155155
return self::$checkedIps[$cacheKey] = false;
156156
}
157157
} else {
158+
if (!filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
159+
return self::$checkedIps[$cacheKey] = false;
160+
}
161+
158162
$address = $ip;
159163
$netmask = 128;
160164
}

‎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
@@ -78,6 +78,7 @@ public function getIpv6Data()
7878
[false, '0.0.0.0/8', '::1'],
7979
[false, '::1', '127.0.0.1'],
8080
[false, '::1', '0.0.0.0/8'],
81+
[true, '::ffff:10.126.42.2', '::ffff:10.0.0.0/0'],
8182
];
8283
}
8384

0 commit comments

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