From b5a07f88712b8d983a3a5dd0ab41344d2b70d91e Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Fri, 13 Nov 2026 11:19:03 +0100
Subject: [PATCH 1/6] feat: make plugin CSP compliant
---
CHANGELOG.md | 4 ++++
setup.php | 1 +
tests/Units/TagItemTest.php | 2 ++
3 files changed, 7 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d3b78d8..c5d2464 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
+### Changed
+
+- Make the plugin compatible with the Content Security Policy
+
### Fixed
- CI: fix Psalm cache directory, declare a unique composer autoloader suffix
diff --git a/setup.php b/setup.php
index 0931f52..dd8b32f 100644
--- a/setup.php
+++ b/setup.php
@@ -187,6 +187,7 @@ function plugin_version_tag()
'author' => 'Teclib\' - Infotel conseil',
'homepage' => 'https://github.com/pluginsGLPI/tag',
'license' => 'GPLv2+',
+ 'csp_compliant' => true,
'requirements' => [
'glpi' => [
'min' => PLUGIN_TAG_MIN_GLPI,
diff --git a/tests/Units/TagItemTest.php b/tests/Units/TagItemTest.php
index b2f81f4..a1f61ab 100644
--- a/tests/Units/TagItemTest.php
+++ b/tests/Units/TagItemTest.php
@@ -127,6 +127,8 @@ public function testShowForTagEncodesLinkedItemValues(): void
$this->assertStringNotContainsString($raw_name, $output);
$this->assertStringContainsString(htmlescape($raw_name), $output);
+ }
+
public function testTagAssociationCreatesLink(): void
{
$this->loginAs(self::TECH_USER);
From e55d08b6117efeb06fc455b3bc4a8b559ca12857 Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Tue, 24 Nov 2026 09:09:13 +0100
Subject: [PATCH 2/6] fix: move inline scripts to JS files for the Content
Security Policy
---
public/js/dropdown.js | 75 +++++++++++++++++++++++++++
public/js/dropdown_init.js | 29 +++++++++++
setup.php | 1 +
templates/dropdown.html.twig | 38 ++------------
templates/question_dropdown.html.twig | 14 -----
5 files changed, 108 insertions(+), 49 deletions(-)
create mode 100644 public/js/dropdown.js
create mode 100644 public/js/dropdown_init.js
diff --git a/public/js/dropdown.js b/public/js/dropdown.js
new file mode 100644
index 0000000..1ed8682
--- /dev/null
+++ b/public/js/dropdown.js
@@ -0,0 +1,75 @@
+/**
+ * -------------------------------------------------------------------------
+ * Tag plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of Tag.
+ *
+ * Tag 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Tag 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 Tag. If not, see .
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2014-2023 by Teclib'.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/tag
+ * -------------------------------------------------------------------------
+ */
+
+(function () {
+ 'use strict';
+
+ // Loaded once per page through ADD_JAVASCRIPT (setup.php); dropdown_init.js calls initMarkers().
+ window.PluginTagDropdown = {
+ colorize: function (marker, $container) {
+ var colors = JSON.parse(marker.getAttribute('data-tag-colors'));
+ var selector = 'select[data-glpi-plugin-tag-dropdown-uuid="' + marker.getAttribute('data-tag-dropdown-uuid') + '"]';
+ import(GLPI_PLUGINS_PATH.tag + '/js/modules/TagDropdownColorizer.js').then(function (m) {
+ new m.GlpiPluginTagTagDropdownColorizer(colors, selector, $container);
+ });
+ },
+ initMarkers: function (scope) {
+ scope.querySelectorAll('[data-tag-colorizer]:not([data-tag-colorizer-ready])').forEach(function (marker) {
+ marker.setAttribute('data-tag-colorizer-ready', '');
+ window.PluginTagDropdown.colorize(marker, $(document));
+ });
+ }
+ };
+
+ $(document).on('glpi-form-editor-question-type-changed', function (event, question, type) {
+ if (type !== 'PluginTagQuestionType') {
+ return;
+ }
+ $(question).find('[data-tag-colorizer]').each(function () {
+ window.PluginTagDropdown.colorize(this, question);
+ });
+ });
+
+ $(document).on('click', '#save_tag', function (e) {
+ e.preventDefault();
+ var $button = $(this);
+ $.ajax({
+ url: $button.attr('data-tag-url'),
+ type: 'POST',
+ data: {
+ 'itemtype': $button.attr('data-tag-itemtype'),
+ 'items_id': $button.data('tagItemsId'),
+ '_plugin_tag_tag_values': $('select[data-glpi-plugin-tag-dropdown-uuid="' + $button.attr('data-tag-dropdown-uuid') + '"]').val(),
+ '_plugin_tag_tag_process_form': 1,
+ }
+ }).done(function () {
+ displayAjaxMessageAfterRedirect();
+ window.glpiUnsavedFormChanges = false;
+ });
+ });
+})();
diff --git a/public/js/dropdown_init.js b/public/js/dropdown_init.js
new file mode 100644
index 0000000..6af1c96
--- /dev/null
+++ b/public/js/dropdown_init.js
@@ -0,0 +1,29 @@
+/**
+ * -------------------------------------------------------------------------
+ * Tag plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of Tag.
+ *
+ * Tag 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Tag 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 Tag. If not, see .
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2014-2023 by Teclib'.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/tag
+ * -------------------------------------------------------------------------
+ */
+
+PluginTagDropdown.initMarkers(document);
diff --git a/setup.php b/setup.php
index dd8b32f..db53983 100644
--- a/setup.php
+++ b/setup.php
@@ -156,6 +156,7 @@ function plugin_init_tag()
// add needed javascript & css files
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['tag'][] = 'js/common.js';
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['tag'][] = 'js/kanban.js';
+ $PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['tag'][] = 'js/dropdown.js';
$PLUGIN_HOOKS[Hooks::ADD_CSS]['tag'][] = 'css/tag.css';
if (Session::isMultiEntitiesMode() && Session::haveRight(PluginTagTag::$rightname, READ)) {
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['tag'][] = 'js/entity.js';
diff --git a/templates/dropdown.html.twig b/templates/dropdown.html.twig
index 45f4570..a692183 100644
--- a/templates/dropdown.html.twig
+++ b/templates/dropdown.html.twig
@@ -64,7 +64,7 @@
{% if show_save_button is defined and show_save_button %}
{% set tooltip_parts = tooltip_parts|merge([
- ''
+ ''
]) %}
{% endif %}
@@ -90,37 +90,5 @@
})
) }}
-
-
-{% if show_save_button is defined and show_save_button %}
-
-{% endif %}
+
+{{ call('Html::script', ['/plugins/tag/js/dropdown_init.js', {}, false])|raw }}
diff --git a/templates/question_dropdown.html.twig b/templates/question_dropdown.html.twig
index b624283..b72523a 100644
--- a/templates/question_dropdown.html.twig
+++ b/templates/question_dropdown.html.twig
@@ -41,17 +41,3 @@
'dropdown_params' : dropdown_params,
'condition' : condition,
} %}
-
-
From 46a05197ef340448076b932187bfcc037b986b42 Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Tue, 24 Nov 2026 09:31:45 +0100
Subject: [PATCH 3/6] fix: CI checks for CSP script files
---
tests/Units/TagTest.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/Units/TagTest.php b/tests/Units/TagTest.php
index a180cc8..5cebdd3 100644
--- a/tests/Units/TagTest.php
+++ b/tests/Units/TagTest.php
@@ -175,9 +175,9 @@ public function testSaveButtonOnClosedTicketTargetsTagDropdown(): void
$crawler = new Crawler($html);
$this->assertCount(1, $crawler->filter('#save_tag'));
- // The save button JS must read the values from the rendered tags select
- $this->assertSame(1, preg_match('/\'_plugin_tag_tag_values\': \$\(\'([^\']+)\'\)\.val\(\)/', $html, $matches));
- $select = $crawler->filter($matches[1]);
+ // The save button JS reads the values from the tags select matching its dropdown uuid
+ $uuid = $crawler->filter('#save_tag')->attr('data-tag-dropdown-uuid');
+ $select = $crawler->filter('select[data-glpi-plugin-tag-dropdown-uuid="' . $uuid . '"]');
$this->assertCount(1, $select);
$this->assertSame('_plugin_tag_tag_values[]', $select->attr('name'));
}
From fbe0bfa28fac698bfec9e8769e8233c81023237a Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Tue, 24 Nov 2026 09:38:30 +0100
Subject: [PATCH 4/6] fix: CI checks for CSP script files
---
tests/Units/TagTest.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/tests/Units/TagTest.php b/tests/Units/TagTest.php
index 5cebdd3..e4195b7 100644
--- a/tests/Units/TagTest.php
+++ b/tests/Units/TagTest.php
@@ -39,7 +39,6 @@
use function Safe\ob_get_clean;
use function Safe\ob_start;
-use function Safe\preg_match;
final class TagTest extends TagTestCase
{
From ee0a370cf56e35030d3487a5dd865010fc318822 Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Tue, 24 Nov 2026 12:16:28 +0100
Subject: [PATCH 5/6] fix: version plugin scripts with the plugin version
Html::script() defaults its cache key to GLPI_VERSION, so a plugin-only upgrade served stale JS files.
---
templates/dropdown.html.twig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/dropdown.html.twig b/templates/dropdown.html.twig
index a692183..0e443c5 100644
--- a/templates/dropdown.html.twig
+++ b/templates/dropdown.html.twig
@@ -91,4 +91,4 @@
) }}
-{{ call('Html::script', ['/plugins/tag/js/dropdown_init.js', {}, false])|raw }}
+{{ call('Html::script', ['/plugins/tag/js/dropdown_init.js', {'version': constant('PLUGIN_TAG_VERSION')}, false])|raw }}
From 99eff939bd14e526dbf515dde601ded90306b223 Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Thu, 26 Nov 2026 15:45:24 +0100
Subject: [PATCH 6/6] review
---
public/js/dropdown.js | 6 +++++-
public/js/dropdown_init.js | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/public/js/dropdown.js b/public/js/dropdown.js
index 1ed8682..33c299f 100644
--- a/public/js/dropdown.js
+++ b/public/js/dropdown.js
@@ -29,7 +29,8 @@
(function () {
'use strict';
- // Loaded once per page through ADD_JAVASCRIPT (setup.php); dropdown_init.js calls initMarkers().
+ // Loaded once per page through ADD_JAVASCRIPT (setup.php), in the page footer.
+ // dropdown_init.js handles markers inserted later (AJAX); markers already in the page are handled below.
window.PluginTagDropdown = {
colorize: function (marker, $container) {
var colors = JSON.parse(marker.getAttribute('data-tag-colors'));
@@ -46,6 +47,9 @@
}
};
+ // Markers rendered inline before the footer (e.g. /Form/Render) ran dropdown_init.js before this file existed.
+ window.PluginTagDropdown.initMarkers(document);
+
$(document).on('glpi-form-editor-question-type-changed', function (event, question, type) {
if (type !== 'PluginTagQuestionType') {
return;
diff --git a/public/js/dropdown_init.js b/public/js/dropdown_init.js
index 6af1c96..604357a 100644
--- a/public/js/dropdown_init.js
+++ b/public/js/dropdown_init.js
@@ -26,4 +26,4 @@
* -------------------------------------------------------------------------
*/
-PluginTagDropdown.initMarkers(document);
+window.PluginTagDropdown?.initMarkers(document);