Skip to content

feat: make plugin CSP compliant - #712

Open
Rom1-B wants to merge 3 commits into
11.0/bugfixesfrom
csp-compliance
Open

Rom1-B wants to merge 3 commits 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 data-datainjection-confirm, handled the same way, replaces the inline window.confirm calls. Behaviour is unchanged.
  • Declares 'csp_compliant' => true in plugin_version_datainjection().

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.

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-datainjection-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.

@Rom1-B
Rom1-B marked this pull request as ready for review November 19, 2026 10:06
@Rom1-B
Rom1-B requested review from a team, Mary-Clb, MyvTsv and RomainLvr and removed request for a team November 19, 2026 10:06
Html::script() defaults its cache key to GLPI_VERSION, so a plugin-only upgrade served stale JS files.
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