Skip to content

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

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 slowlog's remaining 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

  • Charts / summary / details filter views (slowlog.php) — the Go/Clear buttons, filter selects (#logid/#mmethod/#table/#rows/#myuser/#host), time-shift icons and the predefined-timespan select drop their inline onClick/onChange. Each is bound in its own view's ready block to the same applyFilter/clearFilter/applyChartsFilter/applyGraphTimespan/timeshiftGraphFilterLeft/Right functions it already called. Go submit buttons use the existing form-submit binding; Clear buttons (which share a class, not an id) are bound form-scoped.
  • Cancel button — onClick='window.location.assign(...)' → cactiReturnTo class + data-url.
  • Per-field clear glyph (slowlog_details_filter_clear_glyph in includes/slowlog_functions.php) — inline onclick → slowlogClearFilter class + data-url, bound by a delegated handler.

Gate / tests

includes/slowlog_functions.php is measured; a new tests/Unit/SlowlogClearGlyphTest.php covers the changed glyph line. slowlog.php is already in the patch-coverage allowlist. No __()/__esc() calls changed, so check-i18n-pot.php 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 slowlog's remaining inline handlers:

- The charts, summary and details filter views (slowlog.php) drop their inline
  onClick/onChange on the Go/Clear buttons, filter selects, time-shift icons
  and timespan select; each control is bound in its own view's ready block to
  the same applyFilter/clearFilter/applyChartsFilter/applyGraphTimespan/
  timeshift functions it already called. Go submit buttons rely on the existing
  form-submit binding; Clear buttons are bound form-scoped (they share a class,
  not an id).
- The confirmation Cancel button switches from onClick='window.location.assign'
  to the cactiReturnTo class + data-url.
- The per-field clear glyph (slowlog_details_filter_clear_glyph in
  includes/slowlog_functions.php) drops its inline onclick for a
  slowlogClearFilter class + data-url, bound by a delegated handler.

includes/slowlog_functions.php is measured; a new SlowlogClearGlyphTest covers
the changed glyph line. slowlog.php is already in 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

Duplicate chart-form submit bindings trigger two page-load requests per submission.

1 open finding
What changed in this PR

Updates slowlog’s UI event bindings to comply with Cacti’s Content Security Policy.

Changes:

  • Replaces inline handlers with JavaScript bindings and data attributes.
  • Adds clear-filter markup coverage.
  • Documents compatibility steps for older Cacti releases.
File Description
tests/​Unit/​SlowlogClearGlyphTest.php Tests CSP-safe clear-filter markup.
slowlog.php Updates filter, navigation, and Cancel bindings.
README.md Documents older-version Cancel support.
includes/​slowlog_functions.php Removes the clear glyph’s inline handler.
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 slowlog.php Outdated
bmfmancini
bmfmancini previously approved these changes Oct 8, 2026
Removed event handler for charts filter submission.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@TheWitness
TheWitness merged commit 9c4228f into main Oct 8, 2026
5 checks passed
@TheWitness
TheWitness deleted the fix/csp-inline-handlers branch October 8, 2026 01:58
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