Skip to content

feat: make plugin CSP compliant - #89

Merged
Rom1-B merged 6 commits into
11.0/bugfixesfrom
csp-compliance
Nov 27, 2026
Merged

Rom1-B merged 6 commits into
11.0/bugfixesfrom
csp-compliance

Conversation

@Rom1-B

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

Copy link
Copy Markdown
Contributor

Summary

The plugin declares support for the Content Security Policy sent by GLPI.
Audit of the PHP, Twig and JavaScript sources found no inline event handler attribute, no javascript: URL, no <script> tag printed from PHP or created from JavaScript, and no core helper emitting an inline handler, so no code change was needed.

The LDAP select question passes on_change to Dropdown::show(). Core renders it as jQuery change handler evaluated with eval(), not as an onchange attribute, so it is allowed by the CSP ('unsafe-eval') and left unchanged.

Changes

  • setup.php: add 'csp_compliant' => true to plugin_version_advancedforms().
  • CHANGELOG.md: entry under Unreleased.

Compatibility

The change works on GLPI releases with and without the Content Security Policy (glpi-project/glpi#26020 and its follow-up PRs): it relies on no CSP-only core feature, so the minimum GLPI version is unchanged.

Inline scripts are moved to JS files loaded with Html::script() or the add_javascript hook, with data passed through data-* attributes: no <script> is written in templates, and the scripts get the nonce on CSP-enabled GLPI.

Manual test checklist

Keep the browser console open. CSP violations appear as Refused to execute inline event handler or Refused to execute inline script.

  • Form editor, LDAP select question: pick an LDAP directory in the dropdown; the filter input is filled from the server (GetAuthLdapFilter). Select the empty value; the filter is cleared.
  • Form editor, Table question: add a row, open a user or item select column; the AJAX dropdown lists entries and selection works.
  • Form editor, Table question: column type select changes the column configuration panel.
  • Form, Tree cascade dropdown question: selecting a parent loads children and the next level appears.
  • Form, LDAP select question (end user): the dropdown lists the directory entries and the search works.
  • No CSP violation logged on these pages.

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

Choose a reason for hiding this comment

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

The following files are missing the nonce="{{ csp_nonce() }}" on their script tags:

  • templates/editor/question_types/table_config.html.twig:34, lines 270 and 284
  • templates/tree_cascade_dropdown.html.twig:56, lines 100 and 141
  • templates/tree_cascade_dropdown_children.html.twig:51 (loaded by AJAX)
  • templates/table_end_user.html.twig:208
  • templates/reservation_question.html.twig:83
  • templates/timeline/reservation_request.html.twig:107

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

As pointed out by @jdurand-teclib, these inline scripts would be blocked once the CSP is enabled. Note that adding nonce="{{ csp_nonce() }}" directly would break the templates on current 11.0 releases, as the csp_nonce() function does not exist without the CSP. To work with or without it, the scripts should go through Html::scriptBlock() ({% set js %}…{% endset %}{{ call('Html::scriptBlock', [js])|raw }}, as in pluginsGLPI/escalade#532) or be moved to a JS file.

@Lainow Lainow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See previous comment

@jdurand-teclib jdurand-teclib left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An inline script tage remains in templates/destination/email_addresses_field.html.twig

@Rom1-B
Rom1-B merged commit b6682f0 into 11.0/bugfixes Nov 27, 2026
7 checks passed
@Rom1-B
Rom1-B deleted the csp-compliance branch November 27, 2026 13:55
@glpi-project

glpi-project Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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

Target Status
main ⚠️ Drafted with conflicts #99

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