Skip to content

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

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

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

Conversation

@glpi-project

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

Copy link
Copy Markdown
Contributor

Forward-port of #89 to main.

Summary

The plugin declares support for the Content Security Policy sent by GLPI.
Audit of the PHP, Twig and JavaScript sources found no inline event handler attribute, no javascript: URL, no <script> tag printed from PHP or created from JavaScript, and no core helper emitting an inline handler, so no code change was needed.

The LDAP select question passes on_change to Dropdown::show(). Core renders it as jQuery change handler evaluated with eval(), not as an onchange attribute, so it is allowed by the CSP ('unsafe-eval') and left unchanged.

Changes

  • setup.php: add 'csp_compliant' => true to plugin_version_advancedforms().
  • CHANGELOG.md: entry under Unreleased.

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.

  • Form editor, LDAP select question: pick an LDAP directory in the dropdown; the filter input is filled from the server (GetAuthLdapFilter). Select the empty value; the filter is cleared.
  • Form editor, Table question: add a row, open a user or item select column; the AJAX dropdown lists entries and selection works.
  • Form editor, Table question: column type select changes the column configuration panel.
  • Form, Tree cascade dropdown question: selecting a parent loads children and the next level appears.
  • Form, LDAP select question (end user): the dropdown lists the directory entries and the search works.
  • No CSP violation logged on these pages.

@glpi-project

glpi-project Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

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

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

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