Merge pull request #27814 from nextcloud/backport/27758/stable22

[stable22] Fix DnsPinMiddleware resolve pinning bug
This commit is contained in:
Lukas Reschke 2021-07-05 18:38:55 +02:00 committed by GitHub
commit 3f212b8857
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -112,15 +112,22 @@ class DnsPinMiddleware {
$targetIps = $this->dnsResolve($hostName, 0);
foreach ($targetIps as $ip) {
$this->localAddressChecker->ThrowIfLocalIp($ip);
$curlResolves = [];
foreach ($ports as $port) {
$curlEntry = $hostName . ':' . $port . ':' . $ip;
$options['curl'][CURLOPT_RESOLVE][] = $curlEntry;
foreach ($ports as $port) {
$curlResolves["$hostName:$port"] = [];
foreach ($targetIps as $ip) {
$this->localAddressChecker->ThrowIfLocalIp($ip);
$curlResolves["$hostName:$port"][] = $ip;
}
}
// Coalesce the per-host:port ips back into a comma separated list
foreach ($curlResolves as $hostport => $ips) {
$options['curl'][CURLOPT_RESOLVE][] = "$hostport:" . implode(',', $ips);
}
return $handler($request, $options);
};
};