CVE-2022-31143: Exposure of Sensitive Information to an Unauthorized Actor (CWE-200)
value: GLPI stands for Gestionnaire Libre de Parc Informatique and is a Free Asset and IT Management Software package, that provides ITIL Service Desk features, licenses tracking and software auditing. It was found that in affected versions there is an exposure of private information defined in setup of GLPI (like smtp or cas hosts). Note that passwords are not exposed. Users are advised to upgrade to version 10.0.3. There are no known workarounds for this issue.
CWE description: The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.
CVSS v3 base score: 5.3
Published: 2022-09-14T18:15Z
Repository: https://github.com/glpi-project/glpi
Language: PHP
Files changed: front/login.php, src/Html.php, templates/pages/login_error.html.twig
Commit date: 2022-09-14 13:52:37 +0200
Commit message: Do not expose CFG_GLPI on anonymous page

Diff: diff --git a/front/login.php b/front/login.php
index 4684b5d458b..3d00ea91423 100644
--- a/front/login.php
+++ b/front/login.php
@@ -35,10 +35,11 @@
 
 /**
  * @since 0.85
  */
 
+use Glpi\Application\View\TemplateRenderer;
 use Glpi\Toolbox\Sanitizer;
 
 include('../inc/includes.php');
 
 
@@ -86,14 +87,11 @@ $auth = new Auth();
 
 // now we can continue with the process...
 if ($auth->login($login, $password, (isset($_REQUEST["noAUTO"]) ? $_REQUEST["noAUTO"] : false), $remember, $login_auth)) {
     Auth::redirectIfAuthenticated();
 } else {
-   // we have done at least a good login? No, we exit.
-    Html::nullHeader("Login", $CFG_GLPI["root_doc"] . '/index.php');
-    echo '<div class="center b">' . $auth->getErr() . '<br><br>';
-   // Logout whit noAUto to manage auto_login with errors
-    echo '<a href="' . $CFG_GLPI["root_doc"] . '/front/logout.php?noAUTO=1' .
-         str_replace("?", "&", $REDIRECT) . '">' . __('Log in again') . '</a></div>';
-    Html::nullFooter();
+    TemplateRenderer::getInstance()->display('pages/login_error.html.twig', [
+        'error'     => $auth->getErr(),
+        'login_url' => $CFG_GLPI["root_doc"] . '/front/logout.php?noAUTO=1' . str_replace("?", "&", $REDIRECT),
+    ]);
     exit();
 }
diff --git a/src/Html.php b/src/Html.php
index e6156d42c52..8b37f2a3f38 100644
--- a/src/Html.php
+++ b/src/Html.php
@@ -6479,14 +6479,17 @@ HTML;
      */
     public static function getCoreVariablesForJavascript(bool $full = false)
     {
         global $CFG_GLPI;
 
+        // prevent leak of data for non logged sessions
+        $full = $full && (Session::getLoginUserID(true) !== false);
+
         $cfg_glpi = "var CFG_GLPI  = {
-         'url_base': '" . (isset($CFG_GLPI['url_base']) ? $CFG_GLPI["url_base"] : '') . "',
-         'root_doc': '" . $CFG_GLPI["root_doc"] . "',
-      };";
+            'url_base': '" . (isset($CFG_GLPI['url_base']) ? $CFG_GLPI["url_base"] : '') . "',
+            'root_doc': '" . $CFG_GLPI["root_doc"] . "',
+        };";
 
         if ($full) {
             $debug = (isset($_SESSION['glpi_use_mode'])
                    && $_SESSION['glpi_use_mode'] == Session::DEBUG_MODE ? true : false);
             $cfg_glpi = "var CFG_GLPI  = " . json_encode(Config::getSafeConfig(true), $debug ? JSON_PRETTY_PRINT : 0) . ";";
@@ -6497,13 +6500,13 @@ HTML;
             $plugins_path[$key] = Plugin::getWebDir($key, false);
         }
         $plugins_path = 'var GLPI_PLUGINS_PATH = ' . json_encode($plugins_path) . ';';
 
         return self::scriptBlock("
-         $cfg_glpi
-         $plugins_path
-      ");
+            $cfg_glpi
+            $plugins_path
+        ");
     }
 
     /**
      * Get a stylesheet or javascript path, minified if any
      * Return minified path if minified file exists and not in
diff --git a/templates/pages/login_error.html.twig b/templates/pages/login_error.html.twig
new file mode 100644
index 00000000000..a750a9ec6b9
--- /dev/null
+++ b/templates/pages/login_error.html.twig
@@ -0,0 +1,57 @@
+{#
+ # ---------------------------------------------------------------------
+ #
+ # GLPI - Gestionnaire Libre de Parc Informatique
+ #
+ # http://glpi-project.org
+ #
+ # @copyright 2015-2022 Teclib' and contributors.
+ # @copyright 2003-2014 by the INDEPNET Development Team.
+ # @licence   https://www.gnu.org/licenses/gpl-3.0.html
+ #
+ # ---------------------------------------------------------------------
+ #
+ # LICENSE
+ #
+ # This file is part of GLPI.
+ #
+ # This program is free software: you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+ # the Free Software Foundation, either version 3 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ #
+ # ---------------------------------------------------------------------
+ #}
+
+{% extends 'layout/page_card_notlogged.html.twig' %}
+
+{% block content_block %}
+<div class="alert alert-warning">
+    <div class="d-flex align-items-center">
+        <div class="me-4">
+            <i class="ti ti-alert-triangle fa-2x"></i>
+        </div>
+        <div>
+            <h4 class="alert-title">
+                {{ __("Error") }}
+            </h4>
+            <div>
+                {{ error }}
+            </div>
+
+            <a href="{{ login_url }}" class="btn btn-primary mt-3">
+                <i class="ti ti-login"></i>
+                <span>{{ __('Log in again') }}</span>
+            </a>
+        </div>
+    </div>
+</div>
+{% endblock %}

Vulnerable code:    // we have done at least a good login? No, we exit.
    Html::nullHeader("Login", $CFG_GLPI["root_doc"] . '/index.php');
    echo '<div class="center b">' . $auth->getErr() . '<br><br>';
   // Logout whit noAUto to manage auto_login with errors
    echo '<a href="' . $CFG_GLPI["root_doc"] . '/front/logout.php?noAUTO=1' .
         str_replace("?", "&", $REDIRECT) . '">' . __('Log in again') . '</a></div>';
    Html::nullFooter();
         'url_base': '" . (isset($CFG_GLPI['url_base']) ? $CFG_GLPI["url_base"] : '') . "',
         'root_doc': '" . $CFG_GLPI["root_doc"] . "',
      };";
         $cfg_glpi
         $plugins_path
      ");
Fixed code: use Glpi\Application\View\TemplateRenderer;
    TemplateRenderer::getInstance()->display('pages/login_error.html.twig', [
        'error'     => $auth->getErr(),
        'login_url' => $CFG_GLPI["root_doc"] . '/front/logout.php?noAUTO=1' . str_replace("?", "&", $REDIRECT),
    ]);
        // prevent leak of data for non logged sessions
        $full = $full && (Session::getLoginUserID(true) !== false);

            'url_base': '" . (isset($CFG_GLPI['url_base']) ? $CFG_GLPI["url_base"] : '') . "',
            'root_doc': '" . $CFG_GLPI["root_doc"] . "',
        };";
            $cfg_glpi
            $plugins_path
        ");
{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2022 Teclib' and contributors.
 # @copyright 2003-2014 by the INDEPNET Development Team.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% extends 'layout/page_card_notlogged.html.twig' %}

{% block content_block %}
<div class="alert alert-warning">
    <div class="d-flex align-items-center">
        <div class="me-4">
            <i class="ti ti-alert-triangle fa-2x"></i>
        </div>
        <div>
            <h4 class="alert-title">
                {{ __("Error") }}
            </h4>
            <div>
                {{ error }}
            </div>

            <a href="{{ login_url }}" class="btn btn-primary mt-3">
                <i class="ti ti-login"></i>
                <span>{{ __('Log in again') }}</span>
            </a>
        </div>
    </div>
</div>
{% endblock %}