Skip to content

feat: make plugin CSP compliant - #111

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

Description

Make the PDF plugin compatible with the Content Security Policy sent by GLPI.
The "Check all" and "Uncheck all" buttons of the PDF export form relied on inline onclick handlers, which the browser refuses to run under the CSP.
They are now bound from the form's script with jQuery click listeners, calling the same functions with the same arguments.
The plugin declares csp_compliant in setup.php.

Converted patterns

  • templates/preference_form.html.twig: two onclick attributes (handler attributes written directly) replaced by the ids select_all_{{ form_id }} and select_none_{{ form_id }}, with listeners added in the existing $(document).ready block.
  • setup.php: 'csp_compliant' => true added to plugin_version_pdf().
  • CHANGELOG.md: entry under UNRELEASED.

Checked and left unchanged:

  • the <script> blocks in templates/config.html.twig and templates/preference_form.html.twig are literal Twig text, so the nonce is added at compile time;
  • no on_change, no javascript: URL, no Html::addConfirmationOnAction() or confirmaction;
  • inc/simplepdf.class.php only strips <script> tags from user content with preg_replace, it prints none.

Blocked by

Manual test checklist

  • Open the PDF export form of an item, and the PDF export user preferences form.
  • Click "Check all": every table checkbox is checked, the cards get the success border, and the selected counter is updated.
  • Click "Uncheck all": every checkbox is cleared, the borders are removed, and the counter goes to 0.
  • Keep the browser console open: no "Refused to execute inline event handler" or "Refused to execute inline script" message should appear on these pages.

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.

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