Skip to content

[main] feat: make plugin CSP compliant - #726

Open
glpi-project[bot] wants to merge 1 commit into
mainfrom
forward-port/712-to-main
Open

glpi-project[bot] wants to merge 1 commit into
mainfrom
forward-port/712-to-main

Conversation

@glpi-project

@glpi-project glpi-project Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Forward-port of #712 to main.

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.

@glpi-project

glpi-project Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin forward-port/712-to-main
git worktree add --checkout .worktree/forward-port/712-to-main forward-port/712-to-main
cd .worktree/forward-port/712-to-main
git reset --hard HEAD^
git cherry-pick -x fd0e89ee7c9fa9d3a848e9432566b3881b4607b6

@glpi-project glpi-project Bot mentioned this pull request Nov 30, 2026
2 of 4 tasks
@Rom1-B
Rom1-B force-pushed the forward-port/712-to-main branch from 6fc3b7b to 770e3f1 Compare November 30, 2026 10:28
@Rom1-B
Rom1-B marked this pull request as ready for review November 30, 2026 10:28
@Rom1-B
Rom1-B requested review from a team, Mary-Clb, Rom1-B and RomainLvr and removed request for a team November 30, 2026 10:29
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