Skip to content

feat: make plugin CSP compliant - #493

Draft
Rom1-B wants to merge 1 commit into
mainfrom
csp-compliance
Draft

Rom1-B wants to merge 1 commit into
mainfrom
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.
  • This change requires a documentation update.

Description

Make the plugin compatible with the Content Security Policy sent by GLPI (script-src 'nonce-...' 'unsafe-eval') and declare it with 'csp_compliant' => true.
Behaviour is unchanged: the two inline handlers of the migration status page are replaced by data attributes bound from the page's existing script.

Converted patterns:

  • templates/migration_status.html.twig: oninput="glpiGenericobjectUpdateCounter(this)" on the rename input becomes data-genericobject-update-counter, bound by a delegated input listener.
  • templates/migration_status.html.twig: onclick="copyCode()" on the copy button becomes data-genericobject-copy-code, bound by a delegated click listener.
  • setup.php: 'csp_compliant' => true added to plugin_version_genericobject().
  • CHANGELOG.md: entry added under Unreleased.

Not changed: the <script> block of migration_status.html.twig is literal Twig text, so it receives the nonce at compilation.

Blocked by

Manual test checklist

Keep the browser console open: CSP violations are reported there as Refused to execute inline event handler or Refused to execute inline script.

  1. Open the migration status page (plugins/genericobject/front/migration_status.php): the page loads with no CSP error in the console.
  2. Open the rename modal of a type, then type in the "New name" field: the character counter and the "Use system name" preview update while typing, and the length warning appears at the maximum length.
  3. Card "How to Migrate": click "Copy": the command php bin/console migration:genericobject_plugin_to_core is copied and the button shows "Copied" for 2 seconds, then reverts.
  4. Console: no Refused to execute inline event handler message on the page.

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