Skip to content

feat: make plugin CSP compliant - #40

Open
Rom1-B wants to merge 5 commits into
mainfrom
csp-compliance
Open

Rom1-B wants to merge 5 commits into
mainfrom
csp-compliance

Conversation

@Rom1-B

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

Copy link
Copy Markdown
Contributor

Make the plugin compatible with the Content Security Policy sent by GLPI 11, 12 and 13.
Inline check-all handlers and a javascript: sort link are replaced by plugin data attributes and listeners (javascript/listeners.js).
Behaviour is unchanged.
The plugin now declares csp_compliant in plugin_version_deploy().

Converted patterns

  • templates/package/datatable.html.twig: check-all onclick replaced by data-deploy-check-all; sort header javascript:reloadTab() link replaced by a <a href="#" role="button"> button with data-deploy-reload-tab.
  • templates/package/subitem.list.html.twig: check-all onclick replaced by a jQuery click binding in the existing script block.
  • templates/package/subitemtarget.list.html.twig: same as above.
  • templates/computer_group/computer_group_static_list.html.twig: same as above, with a new script block.

The three non-datatable check-all checkboxes keep the default input[type="checkbox"] selector, so data-deploy-check-all (fixed to .massive_action_checkbox) is not used for them.

Not changed

  • src/Computer/GroupDynamic.php: 'onclick' => true is a boolean option of Html::showToolTip(), not an attribute.
  • Literal <script> blocks in Twig templates receive the nonce automatically.

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 there as Refused to execute inline event handler or Refused to execute inline script.

  1. Package, subitem tab: tick the header checkbox, all rows are checked; untick, all rows are unchecked.
  2. Package, subitem target tab: same as step 1.
  3. Computer group, static list: same as step 1.
  4. Package, datatable (massive action list): header checkbox checks and unchecks the rows.
  5. Package datatable: click a column header, the list reloads sorted and the sort direction toggles.
  6. Package datatable with filters and pagination: the sort keeps the active filters and page parameters.

@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, Mary-Clb, MyvTsv and RomainLvr and removed request for a team November 19, 2026 10:05
Html::script() defaults its cache key to GLPI_VERSION, so a plugin-only upgrade served stale JS files.

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

Les fichiers JS doivent être dans un dossier public/js

@Rom1-B
Rom1-B requested a review from MyvTsv November 30, 2026 09:40
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.

2 participants