10000 bug #48421 [HttpFoundation] IPv4-mapped IPv6 addresses incorrectly re… · symfony/symfony@5ac1693 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ac1693

Browse 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

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines 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

Lines 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