`front/config.form.php`: `$CFG_GLPI` used without `global` (undefined variable warning, wrong redirect when GLPI is in a subdirectory)

Aperta Adatta ai principianti
#166 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@whamulti ci sta già lavorando.

Dal 29/10/2026.

  • #167 di @whamulti — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
89/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php
Ambito
backend

Direzione di ricerca

Apri front/config.form.php e ispeziona il ramo else finale che gestisce l’accesso diretto alla pagina di configurazione del plugin. Dichiara $CFG_GLPI come globale in quel punto, poi verifica che il reindirizzamento usi il suo valore root_doc e che gli avvisi sulla variabile non definita non vengano più registrati. L’issue segnala che la correzione funziona con GLPI 11.0.12; non viene menzionato alcun file di test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

GLPI Version

11.0.12 (also reproducible on 11.0.11)

Plugin version

1.4.3 — same code in 1.5.0 and on main/develop as of 2026-10-29

Bug description

The final else branch of front/config.form.php uses $CFG_GLPI without declaring it global:

} else {
    Session::checkRight(Config::$rightname, READ);
    /** @var array $CFG_GLPI */
    Html::redirect($CFG_GLPI['root_doc'] . '/front/config.form.php?forcetab=PluginMetabaseConfig$1');
}

Since GLPI 11, legacy front/ scripts are included from inside a method (Glpi\Controller\LegacyFileLoadController::__invoke()), so they no longer run in the global scope and $CFG_GLPI is null there unless it is declared with global. The @var annotation documents the variable but does not import it.

Consequences when the plugin configuration page is opened directly (e.g. the "configure" icon in Setup > Plugins, which points to plugins/metabase/front/config.form.php):

  1. Two PHP warnings are written to php-errors.log on every access (see log below).
  2. $CFG_GLPI['root_doc'] evaluates to null, so the redirect target becomes /front/config.form.php?.... This happens to work when GLPI is served at the web root, but on an instance installed in a subdirectory (for example https://example.org/glpi, where root_doc is /glpi) the browser is sent outside of GLPI and the configuration page cannot be reached from that link.

Expected: no warning, and a redirect to <root_doc>/front/config.form.php?forcetab=PluginMetabaseConfig$1.

Suggested fix (one line, same pattern used elsewhere in GLPI plugins):

 } else {
     Session::checkRight(Config::$rightname, READ);
     /** @var array $CFG_GLPI */
+    global $CFG_GLPI;
     Html::redirect($CFG_GLPI['root_doc'] . '/front/config.form.php?forcetab=PluginMetabaseConfig$1');
 }

We applied exactly this change locally on a production GLPI 11.0.12 instance: the warnings disappear and the redirect lands on the Metabase configuration tab as expected.

Relevant log output

[2026-10-29 15:38:22] glpi.WARNING:   *** Warning: Undefined variable $CFG_GLPI at config.form.php line 51
  Backtrace :
  ./marketplace/metabase/front/config.form.php:51
  ...Glpi/Controller/LegacyFileLoadController.php:64 require()
  ./vendor/symfony/http-kernel/HttpKernel.php:181    Glpi\Controller\LegacyFileLoadController->__invoke()
  ./vendor/symfony/http-kernel/HttpKernel.php:76     Symfony\Component\HttpKernel\HttpKernel->handleRaw()
  ./vendor/symfony/http-kernel/Kernel.php:208        Symfony\Component\HttpKernel\HttpKernel->handle()
[2026-10-29 15:38:22] glpi.WARNING:   *** Warning: Trying to access array offset on value of type null at config.form.php line 51

Page URL

/plugins/metabase/front/config.form.php (no parameters)

Steps To reproduce

  1. Install and enable the Metabase plugin on GLPI 11.
  2. Log in as a user with config READ right.
  3. Open plugins/metabase/front/config.form.php directly (or click the plugin's configure icon in Setup > Plugins).
  4. Check files/_log/php-errors.log: the two warnings above are logged.
  5. On an instance where GLPI is installed in a subdirectory, observe that the redirect goes to /front/config.form.php (outside of the GLPI path) instead of <root_doc>/front/config.form.php.

Your GLPI setup information

  • PHP 8.2.35, Apache 2.4 (mod_php), Debian 12
  • MariaDB 10.11.19
  • GLPI installed at the web root (root_doc empty), so only the warnings are visible on our side; the wrong redirect follows from the code for subdirectory installs.
Lingua principale
PHP
Stelle
17
Fork
12
Merge medio
1h 47m
PR unite (30g)
5

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pluginsGLPI/metabase

Tutte le issue di pluginsGLPI/metabase

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.