]> 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)
committerCôme Chilliet (Rebase PR Action) <come-nc@users.noreply.github.com>
Tue, 12 Jul 2022 09:49:27 +0000 (09:49 +0000)
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
lib/private/Http/Client/LocalAddressChecker.php

index b233f34b19c63c6aa3f5f81062295449ee96b824..749a1a97c8acfc1248a05b2db417e1d2a3f382ad 100644 (file)
@@ -36,13 +36,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');
                }