Repository navigation
feat: make plugin CSP compliant - #55
Merged
Merged
Conversation
Rom1-B
marked this pull request as ready for review
November 19, 2026 10:07
Rom1-B
requested review from
a team,
Herafia,
Lainow and
jdurand-teclib
and removed request for
a team
November 19, 2026 10:07
Lainow
previously approved these changes
Nov 20, 2026
jdurand-teclib
approved these changes
Nov 25, 2026
|
Backport-action backported this pull request in workflow run 45630626745.
|
2 of 4 tasks
Rom1-B
added a commit
that referenced
this pull request
Nov 25, 2026
2 of 4 tasks
jdurand-teclib
pushed a commit
that referenced
this pull request
Nov 27, 2026
Forward-port of #55 to `main`. ## Checklist before requesting a review *Please delete options that are not relevant.* - [x] 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. - [x] I have updated the CHANGELOG with a short functional description of the fix or new feature. - [ ] This change requires a documentation update. ## Description - It fixes # (issue number, if applicable) - The plugin now works under the GLPI Content Security Policy: no inline event handlers and no `<script>` tags printed from PHP remain. Behaviour is unchanged. - The plugin declares `'csp_compliant' => true` in `plugin_version_jamf()`. Converted patterns: - `templates/import.html.twig`: `onclick` on the Import, Discover now and Clear pending imports buttons replaced by jQuery listeners in the template script. - `templates/merge.html.twig`: `onclick` on the Merge button replaced by a jQuery listener in the template script. - `templates/mdm_commands.html.twig`: `onclick` on each MDM command button replaced by a `data-jamf-mdm-command` attribute and a jQuery listener calling `jamfPlugin.onMDMCommandButtonClick()`. - `templates/inventory_info.html.twig`: the generic `on_click` button option is replaced by an `id`; the click is bound in the `extra_js` script. - `inc/computer.class.php` and `inc/mobiledevice.class.php`: the "Sync now" button no longer carries an `on_click` string; its listener is bound in the generated `extra_js`. - `inc/mobiledevice.class.php`: deprecated `Html::link()` replaced by an escaped `<a href>` (same markup minus an empty `display` attribute). ## 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 are logged there): - Computer or mobile device item, Jamf inventory card: click "Sync now", the device syncs and the page reloads. - Jamf import page: "Import", "Discover now" and "Clear pending imports" trigger their AJAX action and reload. - Jamf merge page: "Merge" sends the merge request. - Jamf MDM commands tab on a device: each command button opens its form or confirmation dialog, and a command without parameters or confirmation is sent directly. - Mobile device with lost mode enabled: the GPS value is a link to Google Maps. - No `Refused to execute inline event handler` or `Refused to execute inline script` message in the console on these pages. ## Screenshots (if appropriate): Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Please delete options that are not relevant.
Description
<script>tags printed from PHP remain. Behaviour is unchanged.'csp_compliant' => trueinplugin_version_jamf().Converted patterns:
templates/import.html.twig:onclickon the Import, Discover now and Clear pending imports buttons replaced by jQuery listeners in the template script.templates/merge.html.twig:onclickon the Merge button replaced by a jQuery listener in the template script.templates/mdm_commands.html.twig:onclickon each MDM command button replaced by adata-jamf-mdm-commandattribute and a jQuery listener callingjamfPlugin.onMDMCommandButtonClick().templates/inventory_info.html.twig: the genericon_clickbutton option is replaced by anid; the click is bound in theextra_jsscript.inc/computer.class.phpandinc/mobiledevice.class.php: the "Sync now" button no longer carries anon_clickstring; its listener is bound in the generatedextra_js.inc/mobiledevice.class.php: deprecatedHtml::link()replaced by an escaped<a href>(same markup minus an emptydisplayattribute).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 are logged there):
Refused to execute inline event handlerorRefused to execute inline scriptmessage in the console on these pages.Screenshots (if appropriate):