Skip to content

[main] feat: make plugin CSP compliant - #536

Draft
glpi-project[bot] wants to merge 1 commit into
mainfrom
forward-port/532-to-main
Draft

glpi-project[bot] wants to merge 1 commit into
mainfrom
forward-port/532-to-main

Conversation

@glpi-project

@glpi-project glpi-project Bot commented Nov 20, 2026

Copy link
Copy Markdown

Forward-port of #532 to main.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

Makes the plugin compatible with the Content Security Policy sent by GLPI 11, 12 and 13, and declares it with 'csp_compliant' => true.
No inline event handler or unnonced inline script remains; behaviour is unchanged.

Converted patterns:

  • inc/history.class.php
    • Inline <script> printed from PHP (form pre-fill of the history reassign buttons) now uses Html::scriptBlock() (pattern d).
    • onclick='full_history.show();' on the "more history" link replaced by an id and a jQuery listener in a Html::scriptBlock() (pattern a).
    • onclick='self.opener.location.href=...; self.close();' on group links in the full history popup replaced by an id and a jQuery listener reading this.href (pattern a).
  • templates/config.html.twig
    • on_change of the "Use the technician's group" dropdown (fields.dropdownArrayField) replaced by an add_data_attributes marker and a delegated jQuery change listener in the existing page script (pattern b).
    • The page <script> is now output through Html::scriptBlock().
  • templates/escalade_form.html.twig
    • The <script> copying the unsaved ticket fields into the escalation form is now output through Html::scriptBlock().
  • setup.php
    • 'csp_compliant' => true added to plugin_version_escalade().

No change to the JS files in public/js/: they are served as script files and contain no inline handler.

Related: glpi-project/glpi#26020 (CSP in GLPI core).
The plugin does not depend on it being backported: Twig scripts use Html::scriptBlock() instead of csp_nonce(), which would be an unknown function on GLPI releases without the CSP. Html::scriptBlock() adds the nonce only on CSP-enabled releases, so the minimum GLPI version is unchanged.

No JS build needed: no file under js/ or public/ was edited.

Screenshots (if appropriate):

Manual test checklist (keep the browser console open, CSP violations show as "Refused to execute inline event handler" or "Refused to execute inline script"):

  1. Setup > Plugins > Escalation, group assignment tab: change "Use the technician's group" between "No" and "First"/"Last"; the "at creation time" and "at modification time" fields and the group borders must show or hide as before.
  2. Ticket form: open the escalation form from the timeline after editing a ticket field without saving; the escalation must keep the unsaved value.
  3. Ticket form with an escalation history: click a group reassign button; the ticket form must submit to climb_group.php with the ticket details pre-filled.
  4. Ticket with more than 10 group changes: click the "more history" link under the history; the full history modal opens.
  5. In the full history modal, click a group name; the ticket opener window navigates to the group and the modal window closes.
  6. Console shows no CSP violation on the ticket form, the config page and the full history popup.

@glpi-project

glpi-project Bot commented Nov 20, 2026

Copy link
Copy Markdown
Author

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin forward-port/532-to-main
git worktree add --checkout .worktree/forward-port/532-to-main forward-port/532-to-main
cd .worktree/forward-port/532-to-main
git reset --hard HEAD^
git cherry-pick -x f1afb9b33253f05c0a60ec6831370601ea670a4e

@glpi-project glpi-project Bot mentioned this pull request Nov 20, 2026
2 of 4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant