Skip to content

feat: make plugin CSP compliant - #89

Open
Rom1-B wants to merge 1 commit into
11.0/bugfixesfrom
csp-compliance
Open

Rom1-B wants to merge 1 commit 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.

Blocked by

  • Add content security policy glpi-project/glpi#26020 (CSP support) and its 11.0 / 12.0 backports. The csp_compliant declaration only takes effect on GLPI releases shipping the CSP.
  • The minimum GLPI version (PLUGIN_ADVANCEDFORMS_MIN_GLPI_VERSION, currently 11.0.7) must be bumped to the first CSP-enabled 11.0 release before merging.

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

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