Repository navigation
security: move inline event handlers to CSP-safe bindings - #117
Merged
Merged
Conversation
Cacti's Content-Security-Policy script-src-attr directive blocks inline event-handler attributes. This converts the plugin's remaining inline handlers, all co-located in each view's existing ready block so they call the same functions they already did: - mikrotik.php: across all ten filter views, the device/rows/type/status/list selects, active/sincereset checkboxes, and Go/Clear/Export buttons drop their inline onChange/onClick and are bound in the view's ready block to applyFilter/clearFilter/exportData. - mikrotik_users.php: the type/rows/status selects and Go/Clear buttons are bound the same way; the confirmation Cancel/Return buttons switch from onClick='cactiReturnTo()' to the CSP-safe cactiReturnTo class. mikrotik.php and mikrotik_users.php are web UI entry points (chdir + include auth.php, top-level execution) that cannot be loaded into the isolated unit process, so their rendered HTML lines are not coverable. They move from the phpunit measured <source> set into the patch-coverage allowlist, matching how every other plugin in the fleet treats its UI entry points; their pure helper functions remain covered via mikrotik_test_load_function(). No i18n calls changed, so cacti.pot is untouched. Cacti 1.2.31+ binds the cactiReturnTo class automatically; the README documents a one-time applySkin() snippet for earlier releases.
TheWitness
requested review from
bmfmancini,
browniebraun and
xmacan
and
a balanced review from Copilot
October 7, 2026 23:01
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Event-handler preservation needs correction, and browser validation remains necessary for CSP, AJAX navigation, and legacy compatibility.
1 open finding
What changed in this PR
Moves the MikroTik plugin’s UI controls from inline event handlers to bindings compatible with Cacti’s Content Security Policy.
Changes:
- Binds filter controls through jQuery and confirmation navigation through
cactiReturnTo. - Documents compatibility steps for Cacti versions below 1.2.31.
- Excludes UI entry points from measured coverage while retaining helper tests.
| File | Description |
|---|---|
| tests/bin/patch-coverage.php | Allowlists unmeasured UI entry points. |
| README.md | Documents legacy navigation compatibility. |
| phpunit.xml | Removes UI entry points from measured sources. |
| mikrotik.php | Rebinds controls across ten filter views. |
| mikrotik_users.php | Rebinds filters and confirmation navigation. |
| CHANGELOG.md | Records CSP and coverage changes. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
bmfmancini
approved these changes
Oct 8, 2026
bmfmancini
approved these changes
Oct 8, 2026
bmfmancini
left a comment
Member
There was a problem hiding this comment.
Reviewed the CSP-safe event bindings; behavior is preserved and checks pass.
bmfmancini
approved these changes
Oct 8, 2026
bmfmancini
left a comment
Member
There was a problem hiding this comment.
Reviewed the CSP-safe event bindings; behavior is preserved and checks pass.
browniebraun
approved these changes
Oct 8, 2026
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
Removes the plugin's remaining inline event-handler attributes so pages comply with Cacti's Content-Security-Policy
script-src-attrdirective. Part of the fleet-wide CSP inline-handler cleanup. Every control is bound in its view's existing ready block to the same function the inline handler already called, so behavior is unchanged.Changes
device/rows/type/status/listselects,active/sinceresetcheckboxes, and Go/Clear/Export buttons drop their inlineonChange/onClickand are bound toapplyFilter/clearFilter/exportData.type/rows/statusselects and Go/Clear buttons are bound the same way; the confirmation Cancel/Return buttons switch fromonClick='cactiReturnTo()'to the CSP-safecactiReturnToclass.Gate / coverage
mikrotik.phpandmikrotik_users.phpare web UI entry points (chdir + include auth.php, top-level execution) that cannot be loaded into the isolated unit process, so their rendered HTML lines are not coverable — the harness already eval-isolates their pure helpers viamikrotik_test_load_function(), which records coverage against aneval()'d codepseudo-file rather than these files. They therefore move from the phpunit measured<source>set into the patch-coverage allowlist, matching how every other plugin in the fleet treats its UI entry points. Their pure helper functions remain exercised by the existing unit tests. No__()/__esc()calls changed, socheck-i18n-pot.phppasses without regeneratingcacti.pot.Compatibility
Cacti 1.2.31+ binds the
cactiReturnToclass automatically. The README documents a one-timeapplySkin()snippet for earlier releases. No shim is baked into core or the plugin.