From 015b6903c2ccdd61a800b57af0787495d8e15fa7 Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Fri, 13 Nov 2026 10:48:18 +0100
Subject: [PATCH 1/3] feat: make plugin CSP compliant
---
CHANGELOG.md | 4 ++
inc/info.class.php | 4 +-
inc/model.class.php | 2 +-
public/js/datainjection.js | 41 +++++++++++++++++++
setup.php | 1 +
templates/clientinjection_result.html.twig | 6 +--
.../clientinjection_upload_file.html.twig | 2 +-
templates/log_results.html.twig | 2 +-
templates/mappings_form.html.twig | 2 +-
9 files changed, 55 insertions(+), 9 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 71714cd4..bb9ed47c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
+### Added
+
+- Make the plugin compatible with the Content Security Policy
+
### Fixed
- Fix the uploaded file name being lost after the client injection upload step
diff --git a/inc/info.class.php b/inc/info.class.php
index 899eb3dc..7d034649 100644
--- a/inc/info.class.php
+++ b/inc/info.class.php
@@ -206,10 +206,10 @@ public static function showFormInfos(PluginDatainjectionModel $model)
echo "
";
echo sprintf(" ", $arrow);
echo "";
- echo sprintf("", $formname) . __s('Check all') . " ";
+ echo sprintf("", htmlescape($formname)) . __s('Check all') . " ";
echo "/ ";
echo "";
- echo sprintf("", $formname) . __s('Uncheck all') . " ";
+ echo sprintf("", htmlescape($formname)) . __s('Uncheck all') . " ";
echo "";
echo " ";
- echo "" . __s('Close') . " ";
+ echo "" . __s('Close') . " ";
echo "";
}
diff --git a/public/js/datainjection.js b/public/js/datainjection.js
index 15893c8a..b1cad457 100644
--- a/public/js/datainjection.js
+++ b/public/js/datainjection.js
@@ -39,3 +39,44 @@ function show_log(num) {
document.getElementById('log'+num+'_table').style.display = 'none';
}
}
+
+document.addEventListener('click', (e) => {
+ const markLink = e.target.closest('[data-datainjection-mark-checkboxes]');
+ if (markLink !== null) {
+ if (markCheckboxes(markLink.dataset.datainjectionMarkCheckboxes)) {
+ e.preventDefault();
+ }
+ return;
+ }
+
+ const unmarkLink = e.target.closest('[data-datainjection-unmark-checkboxes]');
+ if (unmarkLink !== null) {
+ if (unMarkCheckboxes(unmarkLink.dataset.datainjectionUnmarkCheckboxes)) {
+ e.preventDefault();
+ }
+ return;
+ }
+
+ const popupLink = e.target.closest('[data-datainjection-popup]');
+ if (popupLink !== null) {
+ const popup = window.open(
+ popupLink.dataset.datainjectionPopup,
+ 'glpipopup',
+ popupLink.dataset.datainjectionPopupFeatures
+ );
+ popup.focus();
+ e.preventDefault();
+ return;
+ }
+
+ const locationLink = e.target.closest('[data-datainjection-location]');
+ if (locationLink !== null) {
+ location.href = locationLink.dataset.datainjectionLocation;
+ return;
+ }
+
+ if (e.target.closest('[data-datainjection-close-window]') !== null) {
+ e.preventDefault();
+ window.close();
+ }
+});
diff --git a/setup.php b/setup.php
index b411fa92..43b028d6 100644
--- a/setup.php
+++ b/setup.php
@@ -98,6 +98,7 @@ function plugin_version_datainjection()
'homepage' => 'https://github.com/pluginsGLPI/datainjection',
'license' => 'GPLv2+',
'version' => PLUGIN_DATAINJECTION_VERSION,
+ 'csp_compliant' => true,
'requirements' => [
'glpi' => [
'min' => PLUGIN_DATAINJECTION_MIN_GLPI,
diff --git a/templates/clientinjection_result.html.twig b/templates/clientinjection_result.html.twig
index 15ca3f22..fabf3638 100644
--- a/templates/clientinjection_result.html.twig
+++ b/templates/clientinjection_result.html.twig
@@ -44,18 +44,18 @@
-
+
{% if has_pdf %}
-
+
{% endif %}
{% if has_errors %}
-
+
{% endif %}
diff --git a/templates/clientinjection_upload_file.html.twig b/templates/clientinjection_upload_file.html.twig
index 43ffaa20..7f261576 100644
--- a/templates/clientinjection_upload_file.html.twig
+++ b/templates/clientinjection_upload_file.html.twig
@@ -69,7 +69,7 @@
{% else %}
{% set message = __("Watch out, you're about to inject data into GLPI. Are you sure you want to do it ?", 'datainjection') %}
{% endif %}
-
+
{% else %}
{% endif %}
diff --git a/templates/log_results.html.twig b/templates/log_results.html.twig
index 0a8fd8f2..9985986a 100644
--- a/templates/log_results.html.twig
+++ b/templates/log_results.html.twig
@@ -141,6 +141,6 @@
{% endif %}
-
{{ __('Close') }}
+
{{ __('Close') }}
\ No newline at end of file
diff --git a/templates/mappings_form.html.twig b/templates/mappings_form.html.twig
index 1063f0e0..bb76a021 100644
--- a/templates/mappings_form.html.twig
+++ b/templates/mappings_form.html.twig
@@ -32,7 +32,7 @@
-
+
{{ __('See the file', 'datainjection') }}
From 67fb8cc19d6bd2132ccce2ad501728c361099d7f Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Tue, 24 Nov 2026 09:08:28 +0100
Subject: [PATCH 2/3] fix: keep CSP changes working without CSP support and
move inline scripts to JS files
---
public/js/clientinjection.js | 57 +++++++++++++++++++
public/js/datainjection.js | 12 +++-
public/js/injection_progress.js | 7 +++
templates/clientinjection.html.twig | 38 +++----------
templates/clientinjection_injection.html.twig | 8 +--
.../clientinjection_upload_file.html.twig | 2 +-
templates/log_results.html.twig | 2 +-
templates/mappings_form.html.twig | 2 +-
8 files changed, 89 insertions(+), 39 deletions(-)
create mode 100644 public/js/clientinjection.js
diff --git a/public/js/clientinjection.js b/public/js/clientinjection.js
new file mode 100644
index 00000000..8858d50d
--- /dev/null
+++ b/public/js/clientinjection.js
@@ -0,0 +1,57 @@
+/**
+ * -------------------------------------------------------------------------
+ * DataInjection plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of DataInjection.
+ *
+ * DataInjection 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.
+ *
+ * DataInjection 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 DataInjection. If not, see .
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2007-2023 by DataInjection plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/datainjection
+ * -------------------------------------------------------------------------
+ */
+
+$(function() {
+ document.querySelectorAll('[data-datainjection-model-form]:not([data-datainjection-model-form-ready])').forEach((span) => {
+ span.setAttribute('data-datainjection-model-form-ready', '');
+
+ const rand = span.dataset.rand;
+ const uploadUrl = span.dataset.uploadUrl;
+ const resultUrl = span.dataset.resultUrl;
+ const modelId = Number(span.dataset.modelsId);
+ const step = Number(span.dataset.step);
+ const resultStep = Number(span.dataset.resultStep);
+
+ function loadFormForModel(modelId) {
+ if (modelId > 0) {
+ const url = (step === resultStep) ? resultUrl : uploadUrl;
+ $('#span_injection').load(url, { models_id: modelId });
+ }
+ }
+
+ // On model change
+ $('#clientinjection_form' + rand + ' select[name="dropdown_models"]').on('change select2:select', function() {
+ loadFormForModel($(this).val());
+ });
+
+ // Initial load
+ if (modelId > 0) {
+ loadFormForModel(modelId);
+ }
+ });
+});
diff --git a/public/js/datainjection.js b/public/js/datainjection.js
index b1cad457..a6778dad 100644
--- a/public/js/datainjection.js
+++ b/public/js/datainjection.js
@@ -40,6 +40,14 @@ function show_log(num) {
}
}
+document.addEventListener('click', (e) => {
+ const confirmButton = e.target.closest('[data-datainjection-confirm]');
+ if (confirmButton !== null && !window.confirm(confirmButton.dataset.datainjectionConfirm)) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ }
+}, true);
+
document.addEventListener('click', (e) => {
const markLink = e.target.closest('[data-datainjection-mark-checkboxes]');
if (markLink !== null) {
@@ -65,7 +73,9 @@ document.addEventListener('click', (e) => {
popupLink.dataset.datainjectionPopupFeatures
);
popup.focus();
- e.preventDefault();
+ if ('datainjectionPopupPrevent' in popupLink.dataset) {
+ e.preventDefault();
+ }
return;
}
diff --git a/public/js/injection_progress.js b/public/js/injection_progress.js
index 51659c5e..44afdbbc 100644
--- a/public/js/injection_progress.js
+++ b/public/js/injection_progress.js
@@ -99,3 +99,10 @@ function startBatchInjection(container) {
processBatch();
}
+
+$(function() {
+ document.querySelectorAll('[data-datainjection-injection]:not([data-datainjection-injection-ready])').forEach((container) => {
+ container.setAttribute('data-datainjection-injection-ready', '');
+ startBatchInjection(container);
+ });
+});
diff --git a/templates/clientinjection.html.twig b/templates/clientinjection.html.twig
index 590b9cae..5b766831 100644
--- a/templates/clientinjection.html.twig
+++ b/templates/clientinjection.html.twig
@@ -64,37 +64,17 @@
-
+
+ {{ call('Html::script', ['/plugins/datainjection/js/clientinjection.js', {}, false])|raw }}
-
-
\ No newline at end of file
diff --git a/templates/clientinjection_injection.html.twig b/templates/clientinjection_injection.html.twig
index e230d433..edb1d8ee 100644
--- a/templates/clientinjection_injection.html.twig
+++ b/templates/clientinjection_injection.html.twig
@@ -36,6 +36,7 @@
\ No newline at end of file
diff --git a/templates/mappings_form.html.twig b/templates/mappings_form.html.twig
index bb76a021..15a77dba 100644
--- a/templates/mappings_form.html.twig
+++ b/templates/mappings_form.html.twig
@@ -32,7 +32,7 @@
-
+
{{ __('See the file', 'datainjection') }}
From 18c9045435a4498fab017092fe8e5d7f039db15d Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Tue, 24 Nov 2026 12:15:55 +0100
Subject: [PATCH 3/3] 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/clientinjection.html.twig | 2 +-
templates/clientinjection_injection.html.twig | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/templates/clientinjection.html.twig b/templates/clientinjection.html.twig
index 5b766831..be277441 100644
--- a/templates/clientinjection.html.twig
+++ b/templates/clientinjection.html.twig
@@ -72,7 +72,7 @@
data-models-id="{{ models_id }}"
data-step="{{ step }}"
data-result-step="{{ result_step }}">
- {{ call('Html::script', ['/plugins/datainjection/js/clientinjection.js', {}, false])|raw }}
+ {{ call('Html::script', ['/plugins/datainjection/js/clientinjection.js', {'version': constant('PLUGIN_DATAINJECTION_VERSION')}, false])|raw }}
diff --git a/templates/clientinjection_injection.html.twig b/templates/clientinjection_injection.html.twig
index edb1d8ee..be0a711b 100644
--- a/templates/clientinjection_injection.html.twig
+++ b/templates/clientinjection_injection.html.twig
@@ -59,4 +59,4 @@
{{ __('Injection of the file', 'datainjection') }} — 0 / {{ nblines }} {{ __(' lines', 'datainjection') }}
-{{ call('Html::script', ['/plugins/datainjection/js/injection_progress.js', {}, false])|raw }}
\ No newline at end of file
+{{ call('Html::script', ['/plugins/datainjection/js/injection_progress.js', {'version': constant('PLUGIN_DATAINJECTION_VERSION')}, false])|raw }}
\ No newline at end of file