CVE-2020-26253: Origin Validation Error (CWE-346)
value: Kirby is a CMS. In Kirby CMS (getkirby/cms) before version 3.3.6, and Kirby Panel before version 2.5.14 there is a vulnerability in which the admin panel may be accessed if hosted on a .dev domain. In order to protect new installations on public servers that don't have an admin account for the Panel yet, we block account registration there by default. This is a security feature, which we implemented years ago in Kirby 2. It helps to avoid that you forget registering your first admin account on a public server. In this case – without our security block – someone else might theoretically be able to find your site, find out it's running on Kirby, find the Panel and then register the account first. It's an unlikely situation, but it's still a certain risk. To be able to register the first Panel account on a public server, you have to enforce the installer via a config setting. This helps to push all users to the best practice of registering your first Panel account on your local machine and upload it together with the rest of the site. This installation block implementation in Kirby versions before 3.3.6 still assumed that .dev domains are local domains, which is no longer true. In the meantime, those domains became publicly available. This means that our installation block is no longer working as expected if you use a .dev domain for your Kirby site. Additionally the local installation check may also fail if your site is behind a reverse proxy. You are only affected if you use a .dev domain or your site is behind a reverse proxy and you have not yet registered your first Panel account on the public server and someone finds your site and tries to login at `yourdomain.dev/panel` before you register your first account. You are not affected if you have already created one or multiple Panel accounts (no matter if on a .dev domain or behind a reverse proxy). The problem has been patched in Kirby 3.3.6. Please upgrade to this or a later version to fix the vulnerability.
CWE description: The product does not properly verify that the source of data or communication is valid.
CVSS v3 base score: 5.9
Published: 2020-12-08T02:15Z
Repository: https://github.com/getkirby-v2/panel
Language: PHP
Files changed: app/src/panel.php
Commit date: 2020-12-01 11:11:19 +0100
Commit message: Better check for local environments

Diff: diff --git a/app/src/panel.php b/app/src/panel.php
index abcaec4..2030cc8 100644
--- a/app/src/panel.php
+++ b/app/src/panel.php
@@ -491,17 +491,51 @@ class Panel {
     ));
 
   }
 
   public function isLocal() {
-    $localhosts = array('::1', '127.0.0.1', '0.0.0.0');
-    return (
-      in_array(server::get('SERVER_ADDR'), $localhosts) ||
-      server::get('SERVER_NAME') == 'localhost' ||
-      str::endsWith(server::get('SERVER_NAME'), '.localhost') ||
-      str::endsWith(server::get('SERVER_NAME'), '.test')
-    );
+
+    $host = server::get('SERVER_NAME');
+    $ip   = server::get('SERVER_ADDR');
+
+    if ($host === 'localhost') {
+      return true;
+    }
+
+    if (str::endsWith($host, '.localhost') === true) {
+      return true;
+    }
+
+    if (str::endsWith($host, '.local') === true) {
+      return true;
+    }
+
+    if (str::endsWith($host, '.test') === true) {
+      return true;
+    }
+
+    if (in_array($ip, ['::1', '127.0.0.1']) === true) {
+
+      if (
+        isset($_SERVER['HTTP_X_FORWARDED_FOR']) === true &&
+        in_array($_SERVER['HTTP_X_FORWARDED_FOR'], ['::1', '127.0.0.1']) === false
+      ) {
+        return false;
+      }
+
+      if (
+        isset($_SERVER['HTTP_CLIENT_IP']) === true &&
+        in_array($_SERVER['HTTP_CLIENT_IP'], ['::1', '127.0.0.1']) === false
+      ) {
+        return false;
+      }
+
+      // no reverse proxy or the real client also comes from localhost
+      return true;
+    }
+
+    return false;
   }
 
   public function notify($text) {
     s::set('kirby_panel_message', array(
       'type' => 'notification',

Vulnerable code:     $localhosts = array('::1', '127.0.0.1', '0.0.0.0');
    return (
      in_array(server::get('SERVER_ADDR'), $localhosts) ||
      server::get('SERVER_NAME') == 'localhost' ||
      str::endsWith(server::get('SERVER_NAME'), '.localhost') ||
      str::endsWith(server::get('SERVER_NAME'), '.test')
    );
Fixed code: 
    $host = server::get('SERVER_NAME');
    $ip   = server::get('SERVER_ADDR');

    if ($host === 'localhost') {
      return true;
    }

    if (str::endsWith($host, '.localhost') === true) {
      return true;
    }

    if (str::endsWith($host, '.local') === true) {
      return true;
    }

    if (str::endsWith($host, '.test') === true) {
      return true;
    }

    if (in_array($ip, ['::1', '127.0.0.1']) === true) {

      if (
        isset($_SERVER['HTTP_X_FORWARDED_FOR']) === true &&
        in_array($_SERVER['HTTP_X_FORWARDED_FOR'], ['::1', '127.0.0.1']) === false
      ) {
        return false;
      }

      if (
        isset($_SERVER['HTTP_CLIENT_IP']) === true &&
        in_array($_SERVER['HTTP_CLIENT_IP'], ['::1', '127.0.0.1']) === false
      ) {
        return false;
      }

      // no reverse proxy or the real client also comes from localhost
      return true;
    }

    return false;