Repository navigation
security: move inline event handlers into jQuery ready handlers (CSP) - #394
Merged
Merged
Conversation
Replace every inline onClick/onChange attribute (filter selects, Return/Cancel
buttons, device rescan icon, utilities refresh controls) with handlers bound
inside $(function() {}) blocks. Markup rendered by shared or AJAX-refreshed
code uses delegated handlers in js/mactrack.js. All inline <script> tags
already carry plugin_mactrack_csp_nonce(), which falls back to an empty string
on Cacti releases without CactiSecureHeaders, so the change is backport safe.
Also drops a stray quote/bracket from the Return button in mactrack_devices.php
and adds a regression test guarding against inline handlers and un-nonced
script tags.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bmfmancini
approved these changes
Oct 16, 2026
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
CSP-enforced controls and AJAX navigation still need live Cacti browser validation, and the full test suite remains unverified.
0 open findings
What changed in this PR
Updates Device Tracking controls to support Content Security Policy (CSP) restrictions on inline event handlers.
Changes:
- Moves filter and button actions into jQuery handlers, with delegated handling for shared and AJAX-refreshed controls.
- Corrects utilities refresh behavior and stray Return-button text.
- Adds CSP regression checks and documents the changes.
| File | Description |
|---|---|
| tests/Security/InlineHandlersTest.php | Checks inline handlers, JavaScript URLs, and script nonces. |
| mactrack_view_macs.php | Migrates MAC filters and return buttons. |
| mactrack_view_ips.php | Migrates IP filters. |
| mactrack_view_interfaces.php | Migrates interface filters and totals checkbox. |
| mactrack_view_dot1x.php | Migrates session filters. |
| mactrack_view_devices.php | Migrates device-view filters. |
| mactrack_view_arp.php | Migrates ARP filters. |
| mactrack_vendormacs.php | Migrates row-count filtering. |
| mactrack_utilities.php | Binds refresh selection and button separately. |
| mactrack_snmp.php | Migrates return buttons and row-count filtering. |
| mactrack_sites.php | Migrates return buttons. |
| mactrack_macwatch.php | Migrates filters and return buttons. |
| mactrack_macauth.php | Migrates filters and return buttons. |
| mactrack_devices.php | Migrates controls and corrects Return text. |
| mactrack_device_types.php | Migrates filters and return buttons. |
| lib/mactrack_functions.php | Updates shared filters and rescan markup. |
| js/mactrack.js | Adds delegated rescan and return handlers. |
| CHANGELOG.md | Documents CSP compatibility changes. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
TheWitness
added a commit
that referenced
this pull request
Oct 16, 2026
The coverage gate for #394 reported 0/5 changed lines in lib/mactrack_functions.php: the rescan icon in mactrack_format_device_row() and the filter selects in mactrack_site_filter(). Add unit tests that render both and assert the class/data-attribute hooks, the absence of inline onClick/onChange attributes, and the $(function() {}) bindings. Co-authored-by: Copilot <223556219+Copilot@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.
Summary
Moves every inline event-handler attribute in the plugin into
$(function() {})handlers so pages work under a Content-Security-Policy that blocks inline handlers.Changes
onChange='applyFilter()',onClick='applyFilter()') on the devices, device types, sites, MAC auth/watch, vendor MACs, SNMP options, ARP, devices, 802.1x, interfaces, IPs and MACs views, plus the shared sites filter inlib/mactrack_functions.php: handlers are now bound in each page's existing$(function() {})block.onClick='cactiReturnTo()',goTo(...)): now use amactrackReturnclass handled by a delegated handler injs/mactrack.js(the SNMP page binds its own in its inline script).onClick='scan_device(id)'): nowclass='mactrackRescanDevice' data-device-id, handled by a delegated handler injs/mactrack.js, so rows re-rendered by the enable/disable AJAX calls keep working.onChangeand the Refresh button'sonClickare now bound in the page script. The select previously also reloaded onclick(opening the dropdown); it now reloads onchangeonly.<script>already usedplugin_mactrack_csp_nonce(); none were missing it.'>rendered after the "Return" label inmactrack_devices.php.tests/Security/InlineHandlersTest.phpto guard against inline handler attributes /javascript:URLs and un-nonced<script>tags.Backport safety
plugin_mactrack_csp_nonce()returns''on Cacti releases withoutCactiSecureHeaders..on(),.attr(), delegated$(document).on()).Validation
php -lon all changed PHP files.