From e77ed7d0ae76fd37444b62b3804104ccd9cdc543 Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Tue, 10 Nov 2026 15:55:22 +0100
Subject: [PATCH 1/6] feat: make plugin CSP compliant
---
CHANGELOG.md | 4 ++++
setup.php | 1 +
2 files changed, 5 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f381c3c..90d08cc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Add an "Email" form destination, sending a customized email when a form is submitted
+### Changed
+
+- Make the plugin compatible with the Content Security Policy
+
### Fixed
- Fix hidden question not available in anonymous forms
diff --git a/setup.php b/setup.php
index ba4f51f..66f1934 100644
--- a/setup.php
+++ b/setup.php
@@ -93,6 +93,7 @@ function plugin_version_advancedforms(): array
'author' => 'Teclib\'',
'license' => '',
'homepage' => '',
+ 'csp_compliant' => true,
'requirements' => [
'glpi' => [
'min' => PLUGIN_ADVANCEDFORMS_MIN_GLPI_VERSION,
From 820f6fe390c2ea68acb6b52bcbd6c82f7398e671 Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Tue, 24 Nov 2026 09:08:08 +0100
Subject: [PATCH 2/6] fix: move inline scripts to JS files for the Content
Security Policy
---
public/js/reservation_question.js | 56 +++++++++++++++
public/js/reservation_request_timeline.js | 56 +++++++++++++++
public/js/table_config.js | 72 +++++++++++++++++++
public/js/table_end_user.js | 56 +++++++++++++++
public/js/tree_cascade_dropdown.js | 64 +++++++++++++++++
public/js/tree_cascade_dropdown_children.js | 49 +++++++++++++
.../question_types/table_config.html.twig | 39 +++-------
templates/reservation_question.html.twig | 9 +--
templates/table_end_user.html.twig | 6 +-
.../timeline/reservation_request.html.twig | 11 +--
templates/tree_cascade_dropdown.html.twig | 60 +++++-----------
.../tree_cascade_dropdown_children.html.twig | 14 ++--
12 files changed, 385 insertions(+), 107 deletions(-)
create mode 100644 public/js/reservation_question.js
create mode 100644 public/js/reservation_request_timeline.js
create mode 100644 public/js/table_config.js
create mode 100644 public/js/table_end_user.js
create mode 100644 public/js/tree_cascade_dropdown.js
create mode 100644 public/js/tree_cascade_dropdown_children.js
diff --git a/public/js/reservation_question.js b/public/js/reservation_question.js
new file mode 100644
index 0000000..fb1f577
--- /dev/null
+++ b/public/js/reservation_question.js
@@ -0,0 +1,56 @@
+/**
+ * -------------------------------------------------------------------------
+ * advancedforms plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2025 by the advancedforms plugin team.
+ * @license MIT https://opensource.org/licenses/mit-license.php
+ * @link https://github.com/pluginsGLPI/advancedforms
+ * -------------------------------------------------------------------------
+ */
+
+/**
+ * Loaded right after the reservation question markup (templates/reservation_question.html.twig).
+ * Waits for DOM ready on full pages, like the former inline module did.
+ */
+(function () {
+ const ready_attr = 'data-reservation-question-widget-ready';
+
+ const init = () => {
+ const els = [...document.querySelectorAll('[data-reservation-question-widget]:not([' + ready_attr + '])')];
+ if (els.length === 0) {
+ return;
+ }
+ els.forEach((el) => el.setAttribute(ready_attr, ''));
+
+ import('/plugins/advancedforms/js/modules/ReservationQuestionWidget.js').then(({ ReservationQuestionWidget }) => {
+ els.forEach((el) => new ReservationQuestionWidget(el));
+ });
+ };
+
+ if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', init, { once: true });
+ } else {
+ init();
+ }
+})();
diff --git a/public/js/reservation_request_timeline.js b/public/js/reservation_request_timeline.js
new file mode 100644
index 0000000..0c871ff
--- /dev/null
+++ b/public/js/reservation_request_timeline.js
@@ -0,0 +1,56 @@
+/**
+ * -------------------------------------------------------------------------
+ * advancedforms plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2025 by the advancedforms plugin team.
+ * @license MIT https://opensource.org/licenses/mit-license.php
+ * @link https://github.com/pluginsGLPI/advancedforms
+ * -------------------------------------------------------------------------
+ */
+
+/**
+ * Loaded after each reservation request timeline card, on full pages and on AJAX-reloaded timelines.
+ * Idempotent: each card is initialised once.
+ */
+(function () {
+ const ready_attr = 'data-af-reservation-request-timeline-ready';
+
+ const init = () => {
+ const els = [...document.querySelectorAll('[data-af-reservation-request-timeline]:not([' + ready_attr + '])')];
+ if (els.length === 0) {
+ return;
+ }
+ els.forEach((el) => el.setAttribute(ready_attr, ''));
+
+ import('/plugins/advancedforms/js/modules/ReservationRequestTimelineActions.js').then(({ ReservationRequestTimelineActions }) => {
+ els.forEach((el) => new ReservationRequestTimelineActions(el));
+ });
+ };
+
+ if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', init, { once: true });
+ } else {
+ init();
+ }
+})();
diff --git a/public/js/table_config.js b/public/js/table_config.js
new file mode 100644
index 0000000..a35f0d5
--- /dev/null
+++ b/public/js/table_config.js
@@ -0,0 +1,72 @@
+/**
+ * -------------------------------------------------------------------------
+ * advancedforms plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2025 by the advancedforms plugin team.
+ * @license MIT https://opensource.org/licenses/mit-license.php
+ * @link https://github.com/pluginsGLPI/advancedforms
+ * -------------------------------------------------------------------------
+ */
+
+/**
+ * Loaded right after the table question config markup (templates/editor/question_types/table_config.html.twig).
+ * Idempotent: each markup block is initialised once, even when rendered again.
+ */
+(function () {
+ const ready_attr = 'data-af-table-config-ready';
+ const els = [...document.querySelectorAll('[data-af-table-config]:not([' + ready_attr + '])')];
+ if (els.length === 0) {
+ return;
+ }
+ els.forEach((el) => el.setAttribute(ready_attr, ''));
+
+ window.select2_configs = window.select2_configs || {};
+ els.forEach((el) => {
+ const icons = JSON.parse(el.dataset.afTableConfigIcons);
+ window.afTableColumnTypeTemplate = window.afTableColumnTypeTemplate || function (item) {
+ if (!item.id || !icons[item.id]) {
+ return item.text;
+ }
+ return $('', { 'class': 'd-flex align-items-center gap-1' })
+ .append($('', { 'class': icons[item.id] }))
+ .append(document.createTextNode(' ' + item.text));
+ };
+
+ const field_id = 'af-table-type-template-' + el.dataset.afTableConfig;
+ window.select2_configs[field_id] = {
+ type: 'adapt',
+ field_id: field_id,
+ width: '200px',
+ dropdown_css_class: '',
+ placeholder: '',
+ ajax_limit_count: Number(el.dataset.afTableConfigAjaxLimit),
+ templateresult: window.afTableColumnTypeTemplate,
+ templateselection: window.afTableColumnTypeTemplate,
+ };
+ });
+
+ import('/plugins/advancedforms/js/modules/AfTableQuestionConfig.js').then(({ AfTableQuestionConfig }) => {
+ new AfTableQuestionConfig();
+ });
+})();
diff --git a/public/js/table_end_user.js b/public/js/table_end_user.js
new file mode 100644
index 0000000..4074334
--- /dev/null
+++ b/public/js/table_end_user.js
@@ -0,0 +1,56 @@
+/**
+ * -------------------------------------------------------------------------
+ * advancedforms plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2025 by the advancedforms plugin team.
+ * @license MIT https://opensource.org/licenses/mit-license.php
+ * @link https://github.com/pluginsGLPI/advancedforms
+ * -------------------------------------------------------------------------
+ */
+
+/**
+ * Loaded right after the end user table question markup (templates/table_end_user.html.twig).
+ * Waits for DOM ready on full pages, like the former inline module did.
+ */
+(function () {
+ const ready_attr = 'data-af-table-question-ready';
+
+ const init = () => {
+ const els = [...document.querySelectorAll('[data-af-table-question]:not([' + ready_attr + '])')];
+ if (els.length === 0) {
+ return;
+ }
+ els.forEach((el) => el.setAttribute(ready_attr, ''));
+
+ import('/plugins/advancedforms/js/modules/AfTableQuestion.js').then(({ AfTableQuestion }) => {
+ els.forEach((el) => new AfTableQuestion(el));
+ });
+ };
+
+ if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', init, { once: true });
+ } else {
+ init();
+ }
+})();
diff --git a/public/js/tree_cascade_dropdown.js b/public/js/tree_cascade_dropdown.js
new file mode 100644
index 0000000..dec10f3
--- /dev/null
+++ b/public/js/tree_cascade_dropdown.js
@@ -0,0 +1,64 @@
+/**
+ * -------------------------------------------------------------------------
+ * advancedforms plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2025 by the advancedforms plugin team.
+ * @license MIT https://opensource.org/licenses/mit-license.php
+ * @link https://github.com/pluginsGLPI/advancedforms
+ * -------------------------------------------------------------------------
+ */
+
+/**
+ * Loaded after the tree cascade dropdown markup (templates/tree_cascade_dropdown.html.twig).
+ * Each select carries its own config in data attributes.
+ * Waits for DOM ready on full pages, like the former inline modules did.
+ */
+(function () {
+ const ready_attr = 'data-af-tree-cascade-ready';
+
+ const init = () => {
+ const els = [...document.querySelectorAll('select[data-af-tree-cascade]:not([' + ready_attr + '])')];
+ if (els.length === 0) {
+ return;
+ }
+ els.forEach((el) => el.setAttribute(ready_attr, ''));
+
+ import('/plugins/advancedforms/js/modules/AfTreeCascadeDropdown.js').then(({ AfTreeCascadeDropdown }) => {
+ els.forEach((el) => new AfTreeCascadeDropdown({
+ selector_id: el.id,
+ questions_id: Number(el.dataset.afTreeQuestionsId),
+ ajax_limit_count: Number(el.dataset.afTreeAjaxLimit),
+ level: Number(el.dataset.afTreeLevel || 1),
+ next_container_id: el.dataset.afTreeNextContainer,
+ auto_load_parent_id: Number(el.dataset.afTreeAutoLoadParent || 0),
+ }));
+ });
+ };
+
+ if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', init, { once: true });
+ } else {
+ init();
+ }
+})();
diff --git a/public/js/tree_cascade_dropdown_children.js b/public/js/tree_cascade_dropdown_children.js
new file mode 100644
index 0000000..0952baa
--- /dev/null
+++ b/public/js/tree_cascade_dropdown_children.js
@@ -0,0 +1,49 @@
+/**
+ * -------------------------------------------------------------------------
+ * advancedforms plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2025 by the advancedforms plugin team.
+ * @license MIT https://opensource.org/licenses/mit-license.php
+ * @link https://github.com/pluginsGLPI/advancedforms
+ * -------------------------------------------------------------------------
+ */
+
+/**
+ * Loaded after the children select of a tree cascade dropdown, rendered by AJAX.
+ * Triggers the change event once so the first child is applied, as the former inline script did.
+ */
+(function () {
+ const ready_attr = 'data-af-tree-autoselect-ready';
+ const els = [...document.querySelectorAll('select[data-af-tree-autoselect]:not([' + ready_attr + '])')];
+
+ els.forEach((el) => {
+ el.setAttribute(ready_attr, '');
+ setTimeout(() => {
+ const select = document.getElementById(el.id);
+ if (select) {
+ select.dispatchEvent(new Event('change', { bubbles: true }));
+ }
+ }, 50);
+ });
+})();
diff --git a/templates/editor/question_types/table_config.html.twig b/templates/editor/question_types/table_config.html.twig
index d53a701..b452f60 100644
--- a/templates/editor/question_types/table_config.html.twig
+++ b/templates/editor/question_types/table_config.html.twig
@@ -31,19 +31,13 @@
{% set rand = random() %}
-
-
-
+
-
-
-
+{{ call('Html::script', ['/plugins/advancedforms/js/table_config.js', {'version': constant('PLUGIN_ADVANCEDFORMS_VERSION')}, false])|raw }}
diff --git a/templates/reservation_question.html.twig b/templates/reservation_question.html.twig
index 933febd..be19432 100644
--- a/templates/reservation_question.html.twig
+++ b/templates/reservation_question.html.twig
@@ -80,11 +80,4 @@
{# Session-deduped, also loads the FullCalendar locale matching the user language #}
{% do call(['Html', 'requireJs'], ['fullcalendar']) %}
{% endif %}
-
+{{ call('Html::script', ['/plugins/advancedforms/js/reservation_question.js', {'version': constant('PLUGIN_ADVANCEDFORMS_VERSION')}, false])|raw }}
diff --git a/templates/table_end_user.html.twig b/templates/table_end_user.html.twig
index e000dfd..e49df01 100644
--- a/templates/table_end_user.html.twig
+++ b/templates/table_end_user.html.twig
@@ -205,8 +205,4 @@
>