Skip to content

feat: make plugin CSP compliant - #532

Merged
Lainow merged 2 commits into
11.0/bugfixesfrom
csp-compliance
Nov 20, 2026
Merged

Lainow merged 2 commits into
11.0/bugfixesfrom
csp-compliance

Conversation

@Rom1-B

@Rom1-B Rom1-B commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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.

@Rom1-B
Rom1-B marked this pull request as ready for review November 19, 2026 10:05
@Rom1-B
Rom1-B requested review from a team, Herafia, Lainow and jdurand-teclib and removed request for a team November 19, 2026 10:05

@jdurand-teclib jdurand-teclib left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the script tag in inc/ticket.class.php:1353 needs to be <script nonce="{{ csp_nonce() }}">, otherwise some unsaved changes might be lost

Comment thread templates/config.html.twig Resolved
@Rom1-B

Rom1-B commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Good catch, the script lives in escalade_form.html.twig (rendered from ticket.class.php); now output through Html::scriptBlock() for the same backward-compatibility reason, covered by testEscaladeFormDoesNotUseConfiguredApplicationUrl.

@Lainow
Lainow merged commit f1afb9b into 11.0/bugfixes Nov 20, 2026
7 checks passed
@Lainow
Lainow deleted the csp-compliance branch November 20, 2026 13:45
@glpi-project

glpi-project Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Backport-action backported this pull request in workflow run 44747147333.

Target Status
main ⚠️ Drafted with conflicts #536

@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.

4 participants