8000 [HttpFoundation] IPv4-mapped IPv6 addresses incorrectly rejected · symfony/symfony@2170d3c · GitHub
[go: up one dir, main page]

Skip to content

Commit 2170d3c

Browse files
bonroyagefabpot
authored andcommitted
[HttpFoundation] IPv4-mapped IPv6 addresses incorrectly rejected
1 parent 3da1b76 commit 2170d3c

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
@@ -125,17 +125,17 @@ public static function checkIp6($requestIp, $ip)
125125
}
126126

127127
// Check to see if we were given a IP4 $requestIp or $ip by mistake
128-
if (str_contains($requestIp, '.') || str_contains($ip, '.')) {
129-
return self::$checkedIps[$cacheKey] = false;
130-
}
131-
132128
if (!filter_var($requestIp, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
133129
return self::$checkedIps[$cacheKey] = false;
134130
}
135131

136132
if (str_contains($ip, '/')) {
137133
[$address, $netmask] = explode('/', $ip, 2);
138134

135+
if (!filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
136+
return self::$checkedIps[$cacheKey] = false;
137+
}
138+
139139
if ('0' === $netmask) {
140140
return (bool) unpack('n*', @inet_pton($address));
141141
}
@@ -144,6 +144,10 @@ public static function checkIp6($requestIp, $ip)
144144
return self::$checkedIps[$cacheKey] = false;
145145
}
146146
} else {
147+
if (!filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
148+
return self::$checkedIps[$cacheKey] = false;
149+
}
150+
147151
$address = $ip;
148152
$netmask = 128;
149153
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function getIpv6Data()
7777
[false, '0.0.0.0/8', '::1'],
7878
[false, '::1', '127.0.0.1'],
7979
[false, '::1', '0.0.0.0/8'],
80+
[true, '::ffff:10.126.42.2', '::ffff:10.0.0.0/0'],
8081
];
8182
}
8283

0 commit comments

Comments
 (0)
0