Skip to content

feat: make plugin CSP compliant - #712

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

  • It fixes # (issue number, if applicable)
  • Makes the plugin compatible with the Content Security Policy sent by GLPI. Inline event handlers are replaced by data attributes handled by listeners in public/js/datainjection.js, and core data-glpi-confirm replaces the inline window.confirm calls. Behaviour is unchanged.
  • Declares 'csp_compliant' => true in plugin_version_datainjection().

Blocked by: glpi-project/glpi#26020 (CSP) and its 11.0/12.0 backport. The minimum GLPI version (PLUGIN_DATAINJECTION_MIN_GLPI) must be bumped to the first CSP-enabled release before merging, since data-glpi-confirm does nothing on older releases.

Converted patterns

  • inc/info.class.php: "Check all" / "Uncheck all" links, onclick replaced by data-datainjection-mark-checkboxes / data-datainjection-unmark-checkboxes.
  • inc/model.class.php: javascript:window.close() link replaced by data-datainjection-close-window.
  • templates/clientinjection_upload_file.html.twig: submit button onclick="return window.confirm(...)" replaced by data-glpi-confirm.
  • templates/clientinjection_result.html.twig: three links with onclick replaced by data-datainjection-popup / data-datainjection-popup-features / data-datainjection-location.
  • templates/mappings_form.html.twig: preview popup link replaced by data-datainjection-popup / data-datainjection-popup-features.
  • templates/log_results.html.twig: javascript:window.close() link replaced by a button with data-datainjection-close-window.
  • public/js/datainjection.js: delegated click listener for the attributes above.
  • Left as is: <script> blocks in templates/clientinjection.html.twig and templates/clientinjection_injection.html.twig (literal Twig, nonce added at compile time).

Manual test checklist

  • Injection wizard, upload step: click "Launch the import" with the confirm message shown, cancel it (nothing submitted), then confirm (import starts).
  • Model info tab: "Check all" and "Uncheck all" tick and untick the injection lines; the page does not jump to the top.
  • Result step: the log icon opens a 1000x400 popup, the PDF and CSV icons download the export.
  • Mapping form: "See the file" opens a 600x400 popup and stays on the page.
  • Log results popup: "Close" closes the window.
  • Keep the browser console open: no Refused to execute inline event handler or Refused to execute inline script message should appear.

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