Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-09-20 13:46:22 +0300
committerCôme Chilliet <come.chilliet@nextcloud.com>2022-09-20 13:46:22 +0300
commit31117fa7c70de9beb8aa39615e780214b251f519 (patch)
treed70c975e67ff550c9f69bf2ed5535346ff62a25a /lib/private
parent7ac688a2e5c74c890417f25683afc5c0a9a1e000 (diff)
Fix tests for nested v4 in v6
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Http/Client/LocalAddressChecker.php20
1 files changed, 6 insertions, 14 deletions
diff --git a/lib/private/Http/Client/LocalAddressChecker.php b/lib/private/Http/Client/LocalAddressChecker.php
index 274186d0a5a..13a7d062de3 100644
--- a/lib/private/Http/Client/LocalAddressChecker.php
+++ b/lib/private/Http/Client/LocalAddressChecker.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
*/
namespace OC\Http\Client;
+use IPLib\Address\IPv6;
use IPLib\Factory;
use IPLib\ParseStringFlag;
use OCP\Http\Client\LocalServerException;
@@ -48,7 +49,11 @@ class LocalAddressChecker {
return;
}
/* Replace by normalized form */
- $ip = (string)$parsedIp;
+ if ($parsedIp instanceof IPv6) {
+ $ip = (string)($parsedIp->toIPv4() ?? $parsedIp);
+ } else {
+ $ip = (string)$parsedIp;
+ }
$localRanges = [
'100.64.0.0/10', // See RFC 6598
@@ -63,19 +68,6 @@ class LocalAddressChecker {
$this->logger->warning("Host $ip was not connected to because it violates local access rules");
throw new LocalServerException('Host violates local access rules');
}
-
- // Also check for IPv6 IPv4 nesting, because that's not covered by filter_var
- if ((bool)filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && substr_count($ip, '.') > 0) {
- $delimiter = strrpos($ip, ':'); // Get last colon
- $ipv4Address = substr($ip, $delimiter + 1);
-
- if (
- !filter_var($ipv4Address, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) ||
- IpUtils::checkIp($ip, $localRanges)) {
- $this->logger->warning("Host $ip was not connected to because it violates local access rules");
- throw new LocalServerException('Host violates local access rules');
- }
- }
}
public function ThrowIfLocalAddress(string $uri) : void {