Repository navigation
feat: make plugin CSP compliant - #89
Conversation
d482861 to
cceb4a0
Compare
jdurand-teclib
left a comment
There was a problem hiding this comment.
The following files are missing the nonce="{{ csp_nonce() }}" on their script tags:
- templates/editor/question_types/table_config.html.twig:34, lines 270 and 284
- templates/tree_cascade_dropdown.html.twig:56, lines 100 and 141
- templates/tree_cascade_dropdown_children.html.twig:51 (loaded by AJAX)
- templates/table_end_user.html.twig:208
- templates/reservation_question.html.twig:83
- templates/timeline/reservation_request.html.twig:107
Herafia
left a comment
There was a problem hiding this comment.
As pointed out by @jdurand-teclib, these inline scripts would be blocked once the CSP is enabled. Note that adding nonce="{{ csp_nonce() }}" directly would break the templates on current 11.0 releases, as the csp_nonce() function does not exist without the CSP. To work with or without it, the scripts should go through Html::scriptBlock() ({% set js %}…{% endset %}{{ call('Html::scriptBlock', [js])|raw }}, as in pluginsGLPI/escalade#532) or be moved to a JS file.
39c1e1a to
fa75e29
Compare
…ows#88" This reverts commit 00293dd.
fa75e29 to
05148f7
Compare
jdurand-teclib
left a comment
There was a problem hiding this comment.
An inline script tage remains in templates/destination/email_addresses_field.html.twig
|
Backport-action backported this pull request in workflow run 46011301527.
|
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_changetoDropdown::show(). Core renders it as jQuerychangehandler evaluated witheval(), not as anonchangeattribute, so it is allowed by the CSP ('unsafe-eval') and left unchanged.Changes
setup.php: add'csp_compliant' => truetoplugin_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 theadd_javascripthook, with data passed throughdata-*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 handlerorRefused to execute inline script.GetAuthLdapFilter). Select the empty value; the filter is cleared.