Skip to content

feat: make plugin CSP compliant - #172

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

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 GLPI Content Security Policy (script-src nonce, no inline handlers).
  • The Central and self-service dashboard selector no longer relies on an inline onchange handler; the same behaviour is attached from public/metabase.js with a delegated jQuery listener (select2 fires jQuery change events).
  • Sets csp_compliant => true in plugin_version_metabase().

Converted patterns

  • inc/dashboard.class.php (PluginMetabaseDashboard::showForCentral()): on_change option of Dropdown::showFromArray() replaced by add_data_attributes (data-metabase-dashboard-switch = helpdesk or central). Same behaviour: helpdesk reloads the page with ?uuid=, Central calls reloadTab("uuid=<value>").
  • public/metabase.js: new delegated change listener on select[data-metabase-dashboard-switch] implementing the two behaviours above.
  • setup.php (plugin_version_metabase()): csp_compliant => true.
  • CHANGELOG.md: Unreleased entry.

No javascript: URLs, no <script> tags printed from PHP, no Html::addConfirmationOnAction(), Html::link() or confirmaction usage were found.

Blocked by

  • Add content security policy glpi-project/glpi#26020 (CSP support) and its 11.0 / 12.0 backports are not released yet.
  • The minimum GLPI version (PLUGIN_METABASE_MIN_GLPI, currently 11.0.0) must be bumped to the first CSP-enabled 11.0 release before merging, otherwise the dashboard selector silently stops reacting on older GLPI versions.

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. Central > Dashboard tab (Central page): with at least two dashboards visible to the profile, change the dropdown value. The dashboard iframe must reload with the selected dashboard, without a full page reload (reloadTab), and the console must show no CSP error.
  2. Self-service portal (helpdesk, Metabase menu entry): change the dropdown value. The page must reload with ?uuid=<selected> and show the selected dashboard.
  3. Config tab (Setup > General > Metabase): the Save and action buttons still submit (no change expected).
  4. Metabase spec browser (collections page): click an "extract" link. The JSON dialog must still open (existing delegated listener, unchanged).

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