Skip to content

feat: make plugin CSP compliant - #630

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 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

GLPI sends a Content Security Policy (script-src 'nonce-<value>' 'unsafe-eval') on HTML responses.
Inline event handlers, javascript: links and <script> tags printed from PHP were blocked by the browser.
This PR removes them while keeping the same behaviour:

  • handlers are now data attributes (data-order-*) bound by a delegated listener in the new public/js/order.js, loaded with add_javascript;
  • confirmations use data-order-confirm;
  • sort and pagination links use data-order-reload-tab buttons;
  • inline scripts printed from PHP go through Html::scriptBlock() or are bound right after their markup;
  • 'csp_compliant' => true is declared in plugin_version_order().

Converted patterns

  • inc/surveysupplier.class.php: rateit <script> via Html::scriptBlock(); check all / uncheck all links.
  • inc/order_supplier.class.php, inc/reference_supplier.class.php, inc/bill.class.php: check all / uncheck all links.
  • inc/order_item.class.php: check all / uncheck all links; add-reference checkbox bound from a script; generation show/hide link.
  • inc/reception.class.php: reception show/hide link; two "Select" buttons (data-order-select-*); bulk delivery link bound from a script.
  • inc/order.class.php: three confirm submit buttons (cancel order, cancel validation request, edit order) use data-order-confirm.
  • templates/order_getitems.html.twig, templates/order_link_item.html.twig: check all checkbox, sort links, pagination links, "Select" button, inline edit cells and cancel buttons, and the expand/collapse script that rewrote reload links.
  • public/js/order.js: new file, delegated listeners for the data-order-* attributes.
  • setup.php: add_javascript hook and csp_compliant flag.
  • CHANGELOG.md: Unreleased entry.

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

  1. Order items, bills, reference suppliers and supplier survey tabs: "Check all" and "Uncheck all" tick and untick the rows, and the page does not scroll to the top.
  2. Order items, reception and bills tabs: the plus icon of each line shows or hides its detail block and swaps the icon.
  3. Edit order items: the "add reference" checkbox shows or hides the reference column.
  4. Reception tab: "Select" next to the number field checks that many lines (top and bottom).
  5. Reception tab: "Take item delivery (bulk)" opens the bulk reception form.
  6. Order form: "Cancel order", "Cancel ask for validation" and "Edit order" ask for confirmation; cancelling the dialog keeps the order unchanged.
  7. Order items list: clicking a column header sorts; the page buttons and the "Entries to show" dropdown reload the list; "Expand all" / "Collapse all" keeps sort and pagination links working.
  8. Order summary and detail tables: clicking a price, discount or quantity opens the edit field, and "Cancel" closes it. Note: detail quantity editing was already broken before this PR (the function it calls is not defined) and is unchanged.
  9. Massive action tables: the header checkbox ticks all rows.

@Rom1-B
Rom1-B marked this pull request as ready for review November 19, 2026 10:08
@Rom1-B
Rom1-B requested review from a team, Mary-Clb, MyvTsv and RomainLvr and removed request for a team November 19, 2026 10:08
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