From e38ddbb718e043e6074d9bf21dbc9b2c22f8f1a3 Mon Sep 17 00:00:00 2001 From: Rom1-B <8530352+Rom1-B@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:02:00 +0100 Subject: [PATCH] feat: make plugin CSP compliant --- CHANGELOG.md | 6 +++++ front/config.form.php | 5 +--- hook.php | 6 ++--- inc/config.class.php | 63 +++++++++++++++++++++++++++++++++++-------- public/left.php | 3 ++- setup.php | 1 + 6 files changed, 65 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c69fde..559f9d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Changed + +- Make the plugin compatible with the Content Security Policy + ## [1.20.4] - 2026-11-05 ### Fixed diff --git a/front/config.form.php b/front/config.form.php index 824f815..269b4ff 100644 --- a/front/config.form.php +++ b/front/config.form.php @@ -55,10 +55,7 @@ } else { Html::header(__s('Setup'), $_SERVER['PHP_SELF'], 'config', 'plugin'); // close frame if open - echo " "; + echo Html::scriptBlock('if (top != self) top.location = self.location;'); } Html::footer(); diff --git a/hook.php b/hook.php index a706ba3..8c99417 100644 --- a/hook.php +++ b/hook.php @@ -285,7 +285,7 @@ function plugin_treeview_uninstall() function plugin_item_update_treeview($item) { if (in_array('locations_id', $item->updates)) { - echo ""; + echo Html::scriptBlock('parent.left.location.reload(true);'); } } @@ -295,7 +295,7 @@ function plugin_item_update_treeview($item) */ function plugin_treeview_reload($item) { - echo ""; + echo Html::scriptBlock('parent.left.location.reload(true);'); } @@ -306,6 +306,6 @@ function plugin_change_entity_Treeview() && (isset($_SESSION['glpi_plugin_treeview_loaded']) && $_SESSION['glpi_plugin_treeview_loaded'] == 1) ) { - echo ""; + echo Html::scriptBlock('parent.left.location.reload(true);'); } } diff --git a/inc/config.class.php b/inc/config.class.php index ebb8c0b..0fd993e 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -31,6 +31,8 @@ use Glpi\DBAL\QueryExpression; use function Safe\json_encode; +use function Safe\ob_get_clean; +use function Safe\ob_start; /** * Contains the display configuration of the treeview @@ -164,10 +166,8 @@ public function seeTreeview() $CFG_GLPI['root_doc'] . "/pics/favicon.ico' >\n"; // Must be always the top window - echo ''; + echo Html::scriptBlock('if (top != self) top.location = self.location;'); + echo ''; echo "