]> source.dussan.org Git - nextcloud-server.git/commitdiff
Refactor local IP if and set strict to true for in_array
authorCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 28 Jun 2022 09:35:45 +0000 (11:35 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Tue, 26 Jul 2022 09:45:29 +0000 (09:45 +0000)
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
lib/private/Http/Client/LocalAddressChecker.php

index cc916349ebdcd92f4c03b35af5720a40761e4306..34a04a75c7e34f0597e8ad9ab94de79c860c166f 100644 (file)
@@ -37,13 +37,13 @@ class LocalAddressChecker {
        }
 
        public function ThrowIfLocalIp(string $ip) : void {
-               if ((bool)filter_var($ip, FILTER_VALIDATE_IP) && !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
-                       $this->logger->warning("Host $ip was not connected to because it violates local access rules");
-                       throw new LocalServerException('Host violates local access rules');
-               }
-
                $localIps = ['100.100.100.200'];
-               if ((bool)filter_var($ip, FILTER_VALIDATE_IP) && in_array($ip, $localIps)) {
+               if (
+                       (bool)filter_var($ip, FILTER_VALIDATE_IP) &&
+                       (
+                               !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) ||
+                               in_array($ip, $localIps, true)
+                       )) {
                        $this->logger->warning("Host $ip was not connected to because it violates local access rules");
                        throw new LocalServerException('Host violates local access rules');
                }