CVE-2022-35946: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
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. In affected versions request input is not properly validated in the plugin controller and can be used to access low-level API of Plugin class. An attacker can, for instance, alter database data. Attacker must have "General setup" update rights to be able to perform this attack. Users are advised to upgrade to version 10.0.3. Users unable to upgrade should remove the `front/plugin.form.php` script.
CWE description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
CVSS v3 base score: 6.5
Published: 2022-09-14T18:15Z
Repository: https://github.com/glpi-project/glpi
Language: PHP
Files changed: front/plugin.form.php
Commit date: 2022-09-14 13:54:05 +0200
Commit message: Filter allowed methods in plugin form controller

Diff: diff --git a/front/plugin.form.php b/front/plugin.form.php
index 8f47e5814557..94ca5bf1d48b 100644
--- a/front/plugin.form.php
+++ b/front/plugin.form.php
@@ -41,18 +41,30 @@ include('../inc/includes.php');
 
 Session::checkRight("config", UPDATE);
 
 $plugin = new Plugin();
 
-if (
-    isset($_POST['action'])
-    && isset($_POST['id'])
-) {
-    if (method_exists($plugin, $_POST['action'])) {
-        call_user_func([$plugin, $_POST['action']], $_POST['id']);
-    } else {
-        echo "Action " . $_POST['action'] . " undefined";
-    }
-    Html::back();
+$id     = isset($_POST['id']) && is_numeric($_POST['id']) ? (int)$_POST['id'] : null;
+$action = $id > 0 && isset($_POST['action']) ? $_POST['action'] : null;
+
+switch ($action) {
+    case 'install':
+        $plugin->install($id);
+        break;
+    case 'activate':
+        $plugin->activate($id);
+        break;
+    case 'unactivate':
+        $plugin->unactivate($id);
+        break;
+    case 'uninstall':
+        $plugin->uninstall($id);
+        break;
+    case 'clean':
+        $plugin->clean($id);
+        break;
+    default:
+        Html::displayErrorAndDie('Lost');
+        break;
 }
 
-Html::displayErrorAndDie('Lost');
+Html::back();

Vulnerable code: if (
    isset($_POST['action'])
    && isset($_POST['id'])
) {
    if (method_exists($plugin, $_POST['action'])) {
        call_user_func([$plugin, $_POST['action']], $_POST['id']);
    } else {
        echo "Action " . $_POST['action'] . " undefined";
    }
    Html::back();
Html::displayErrorAndDie('Lost');
Fixed code: $id     = isset($_POST['id']) && is_numeric($_POST['id']) ? (int)$_POST['id'] : null;
$action = $id > 0 && isset($_POST['action']) ? $_POST['action'] : null;

switch ($action) {
    case 'install':
        $plugin->install($id);
        break;
    case 'activate':
        $plugin->activate($id);
        break;
    case 'unactivate':
        $plugin->unactivate($id);
        break;
    case 'uninstall':
        $plugin->uninstall($id);
        break;
    case 'clean':
        $plugin->clean($id);
        break;
    default:
        Html::displayErrorAndDie('Lost');
        break;
Html::back();