]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use new dependency to normalize IPs
authorCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 20 Sep 2022 10:34:04 +0000 (12:34 +0200)
committerCôme Chilliet <come.chilliet@nextcloud.com>
Mon, 14 Nov 2022 10:14:39 +0000 (11:14 +0100)
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
lib/private/Http/Client/LocalAddressChecker.php

index 8c86cbabf07642f93ffadeec35d4364ac8f8f3ff..ec73fe1c44ec39e63fb4a5eb9a1d742a01ab0138 100644 (file)
@@ -25,6 +25,8 @@ declare(strict_types=1);
  */
 namespace OC\Http\Client;
 
+use IPLib\Factory;
+use IPLib\ParseStringFlag;
 use OCP\Http\Client\LocalServerException;
 use Psr\Log\LoggerInterface;
 use OC\Http\IpUtils;
@@ -37,6 +39,17 @@ class LocalAddressChecker {
        }
 
        public function ThrowIfLocalIp(string $ip) : void {
+               $parsedIp = Factory::parseAddressString(
+                       $ip,
+                       ParseStringFlag::IPV4_MAYBE_NON_DECIMAL | ParseStringFlag::IPV4ADDRESS_MAYBE_NON_QUAD_DOTTED
+               );
+               if ($parsedIp === null) {
+                       /* Not an IP */
+                       return;
+               }
+               /* Replace by normalized form */
+               $ip = (string)$parsedIp;
+
                $localRanges = [
                        '100.64.0.0/10', // See RFC 6598
                        '192.0.0.0/24', // See RFC 6890