Skip to content

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

Merged
jdurand-teclib merged 1 commit into
mainfrom
forward-port/55-to-main
Nov 27, 2026
Merged

jdurand-teclib merged 1 commit into
mainfrom
forward-port/55-to-main

Conversation

@glpi-project

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

Copy link
Copy Markdown

Forward-port of #55 to main.

Checklist before requesting a review

Please delete options that are not relevant.

  • 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.

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):

@glpi-project

glpi-project Bot commented Nov 25, 2026

Copy link
Copy Markdown
Author

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

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

@glpi-project glpi-project Bot mentioned this pull request Nov 25, 2026
2 of 4 tasks
@Rom1-B
Rom1-B force-pushed the forward-port/55-to-main branch from 795c627 to faee095 Compare November 25, 2026 14:25
@Rom1-B
Rom1-B marked this pull request as ready for review November 26, 2026 15:04
@Rom1-B
Rom1-B requested review from a team, Rom1-B, RomainLvr and jdurand-teclib and removed request for a team November 26, 2026 15:04
@jdurand-teclib
jdurand-teclib merged commit f603183 into main Nov 27, 2026
7 checks passed
@jdurand-teclib
jdurand-teclib deleted the forward-port/55-to-main branch November 27, 2026 10:09
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.

2 participants