Skip to content

security: move inline event handlers to CSP-safe bindings - #131

Merged
TheWitness merged 2 commits into
mainfrom
fix/csp-inline-handlers
Oct 8, 2026
Merged

TheWitness merged 2 commits into
mainfrom
fix/csp-inline-handlers

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

Removes the plugin's inline event-handler attributes so pages comply with Cacti's Content-Security-Policy script-src-attr directive. Part of the fleet-wide CSP inline-handler cleanup.

Changes

  • Cancel buttons (servcheck_ca.php, servcheck_credential.php, servcheck_proxy.php, servcheck_restapi.php, servcheck_test.php) — switch from onClick='cactiReturnTo()' to the CSP-safe cactiReturnTo class.
  • Filter "rows" selects (CA, credential, proxy pages) — drop the inline onChange='applyFilter()' and bind in each page's existing ready block via change(). On the CA/proxy pages the existing #rows binding used click() (which never fires for a <select>); credential had no #rows binding at all — both are corrected.
  • tests/bin/patch-coverage.php — allowlist the five web-UI entry points (not loadable in the isolated unit process).
  • README.md / CHANGELOG.md — "Cacti compatibility" note + changelog entry.

Gate / i18n

The changed UI files are not in the measured source set; they're allowlisted. No __()/__esc() calls were added, removed, or modified, so the check-i18n-pot.php gate passes without regenerating cacti.pot.

Compatibility

Cacti 1.2.31+ binds the cactiReturnTo class automatically. The README documents a one-time applySkin() snippet for earlier releases. No shim is baked into core or the plugin.

Cacti's Content-Security-Policy script-src-attr directive blocks inline
event-handler attributes. This converts the plugin's remaining inline
handlers:

- The confirmation-page Cancel buttons across servcheck_ca.php,
  servcheck_credential.php, servcheck_proxy.php, servcheck_restapi.php and
  servcheck_test.php switch from onClick='cactiReturnTo()' to the CSP-safe
  cactiReturnTo class.
- The filter "rows" selects on the CA, credential and proxy pages drop their
  inline onChange='applyFilter()' and are bound in each page's existing ready
  block via change() (not click(), which never fired for a <select>).

The changed UI files are web entry points not loadable in the isolated unit
process, so they are added to the patch-coverage allowlist. 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cancel buttons no longer work out of the box on the declared minimum Cacti versions.

1 open finding
What changed in this PR

Moves UI event handling to CSP-safe JavaScript bindings.

Changes:

  • Replaces inline Cancel and filter handlers.
  • Documents Cacti compatibility requirements.
  • Allowlists UI entry points from patch coverage.
File Description
servcheck_ca.php Updates Cancel and rows handlers.
servcheck_credential.php Adds CSP-safe rows binding.
servcheck_proxy.php Corrects rows event binding.
servcheck_restapi.php Updates Cancel buttons.
servcheck_test.php Updates confirmation Cancel buttons.
tests/​bin/​patch-coverage.php Allowlists UI entry points.
README.md Documents pre-1.2.31 workaround.
CHANGELOG.md Records the CSP cleanup.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread README.md
bmfmancini
bmfmancini previously approved these changes Oct 8, 2026

@bmfmancini bmfmancini left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the Cancel and filter bindings; behavior is preserved and checks pass.

@TheWitness
TheWitness merged commit 5a42006 into main Oct 8, 2026
3 checks passed
@TheWitness
TheWitness deleted the fix/csp-inline-handlers branch October 8, 2026 02:08
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.

4 participants