Skip to content

feat: make plugin CSP compliant - #1350

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

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

Conversation

@Rom1-B

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

Copy link
Copy Markdown
Contributor

Summary

The plugin no longer relies on inline event handlers, javascript: URLs or <script> tags printed from PHP, so it keeps working under the Content Security Policy sent by GLPI.
Behaviour is unchanged: the same functions are called, the listeners are attached from <script> blocks printed right after the markup.
The plugin declares csp_compliant in plugin_version_fields().

Converted patterns

  • inc/container.class.php (showFormSubtype()): two <script> tags printed from PHP are now built with Html::scriptBlock().
  • inc/field.class.php (showForm() field list): the "Add a new field" link used href="javascript:viewAddField...()"; it is now href="#" with a click listener (preventDefault()) attached in the script block that defines viewAddField....
  • inc/labeltranslation.class.php (showTranslations()):
    • the "Add a new translation" link used href="javascript:addTranslation...()"; it is now href="#" with a click listener attached in the same script block.
    • the translation rows used an onClick attribute; the row now has an id and the listener is attached in the per-row script block.
  • setup.php: 'csp_compliant' => true added to plugin_version_fields().
  • CHANGELOG.md: entry under Unreleased.

Not changed: literal <script> blocks in the Twig templates (templates/forms/status_override.html.twig, templates/forms/status_overrides.html.twig, templates/container_display_conditions.html.twig, templates/question_type_administration.html.twig), which receive the nonce at compile time.

Blocked by

  • Add content security policy glpi-project/glpi#26020 (CSP support) and its 11.0 and 12.0 backports: the plugin relies on the nonce being added to scripts printed by Html::scriptBlock().
  • The minimum GLPI version (PLUGIN_FIELDS_MIN_GLPI) must be raised to the first CSP-enabled release before merging.

Manual test checklist

Keep the browser console open: a CSP violation shows as Refused to execute inline event handler or Refused to execute inline script.

  1. Open an item with a container displayed in a tab block, then click "Add a new field": the field form loads under the link and no console error appears.
  2. On an item with a label translation block, click "Add a new translation": the translation form loads in the block.
  3. In the same block, click a translation row: the edit form loads. Clicking the row checkbox still selects it and also opens the edit form, as before.
  4. Open the container form with a "domtab" type and pick a subtype: the subtype dropdown shows and hides the tab selection as before.

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