8000 Merge branch '6.0' into 6.1 · symfony/http-foundation@b54cce1 · GitHub
[go: up one dir, main page]

Skip to content

Commit b54cce1

Browse files
Merge branch '6.0' into 6.1
* 6.0: [HttpFoundation] IPv4-mapped IPv6 addresses incorrectly rejected Minor (comment only), part 2 [RateLimiter] Add typecast to Reservation::wait [FrameworkBundle] Remove check of undefined service in mailer assertions [VarDumper] Ignore \Error in __debugInfo()
2 parents f58e332 + 3af910b commit b54cce1

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

IpUtils.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,17 @@ public static function checkIp6(string $requestIp, string $ip): bool
114114
}
115115

116116
// Check to see if we were given a IP4 $requestIp or $ip by mistake
117-
if (str_contains($requestIp, '.') || str_contains($ip, '.')) {
118-
return self::$checkedIps[$cacheKey] = false;
119-
}
120-
121117
if (!filter_var($requestIp, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
122118
return self::$checkedIps[$cacheKey] = false;
123119
}
124120

125121
if (str_contains($ip, '/')) {
126122
[$address, $netmask] = explode('/', $ip, 2);
127123

124+
if (!filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
125+
return self::$checkedIps[$cacheKey] = false;
126+
}
127+
128128
if ('0' === $netmask) {
129129
return (bool) unpack('n*', @inet_pton($address));
130130
}
@@ -133,6 +133,10 @@ public static function checkIp6(string $requestIp, string $ip): bool
133133
return self::$checkedIps[$cacheKey] = false;
134134
}
135135
} else {
136+
if (!filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
137+
return self::$checkedIps[$cacheKey] = false;
138+
}
139+
136140
$address = $ip;
137141
$netmask = 128;
138142
}

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