Skip to content

feat: make plugin CSP compliant - #55

Merged
jdurand-teclib merged 3 commits into
11.0/bugfixesfrom
csp-compliance
Nov 25, 2026
Merged

jdurand-teclib merged 3 commits into
11.0/bugfixesfrom
csp-compliance

Conversation

@Rom1-B

@Rom1-B Rom1-B commented Nov 13, 2026 •

Copy link
Copy Markdown

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

@Rom1-B
Rom1-B marked this pull request as ready for review November 19, 2026 10:07
@Rom1-B
Rom1-B requested review from a team, Herafia, Lainow and jdurand-teclib and removed request for a team November 19, 2026 10:07
Lainow
Lainow previously approved these changes Nov 20, 2026
@Rom1-B
Rom1-B requested a review from Lainow November 24, 2026 08:53
@jdurand-teclib
jdurand-teclib merged commit 97519eb into 11.0/bugfixes Nov 25, 2026
7 checks passed
@jdurand-teclib
jdurand-teclib deleted the csp-compliance branch November 25, 2026 14:07
@glpi-project

glpi-project Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Backport-action backported this pull request in workflow run 45630626745.

Target Status
main ⚠️ Drafted with conflicts #58

@glpi-project glpi-project Bot mentioned this pull request Nov 25, 2026
2 of 4 tasks
Rom1-B added a commit that referenced this pull request Nov 25, 2026
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>
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.

3 participants