Skip to content

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

Closed
TheWitness wants to merge 2 commits into
developfrom
fix/csp-inline-handlers
Closed

TheWitness wants to merge 2 commits into
developfrom
fix/csp-inline-handlers

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

Removes syslog'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

  • Cancel / Return buttons (syslog_alerts.php, syslog_dashboards.php, syslog_device_rules.php, syslog_removal.php, syslog_reports.php, syslog_saved_searches.php) — onClick='cactiReturnTo()' → cactiReturnTo class.
  • Filter selects (all pages + the syslog_form_callback-generated program select) — drop inline onChange='applyFilterX()' for a syslogFilter class + data-onchange attribute naming the function. A single delegated handler in js/functions.js reads data-onchange and calls that function, so each page keeps its own applyFilter/applyFilterAlerts/applyFilterRemoval/applyFilterReports/applyFilterDashboards/applyFilterSavedSearches behaviour.
  • Collapse-filters toggle — inline onclick → delegated #syslog_search_toggle click binding.

Gate / i18n

All changed pages are already in the patch-coverage allowlist (no measured handlers touched). 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 syslog's remaining inline handlers:

- The confirmation-page Cancel/Return buttons across syslog_alerts.php,
  syslog_dashboards.php, syslog_device_rules.php, syslog_removal.php,
  syslog_reports.php and syslog_saved_searches.php switch from
  onClick='cactiReturnTo()' to the CSP-safe cactiReturnTo class.
- The filter selects on every page (and the syslog_form_callback-generated
  program select) drop their inline onChange='applyFilterX()' for a
  syslogFilter class + data-onchange attribute naming the function; a single
  delegated handler in js/functions.js reads data-onchange and calls the same
  function, so each page keeps its own applyFilter/applyFilterAlerts/
  applyFilterRemoval/applyFilterReports/applyFilterDashboards/
  applyFilterSavedSearches behaviour.
- The collapse-filters toggle button drops its inline onclick in favour of a
  delegated #syslog_search_toggle click binding.

All changed pages are 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

Two confirmation forms misclassify Continue buttons, dynamic selects can emit duplicate class attributes, and supported older Cacti releases regress without core modifications.

4 open findings
What changed in this PR

Moves inline event handlers to CSP-safe delegated bindings across Syslog pages.

Changes:

  • Replaces inline filter and toggle handlers with delegated JavaScript.
  • Migrates Cancel/Return buttons to class-based handling.
  • Documents compatibility and updates the changelog.
File Description
syslog.php Migrates filter and toggle handlers.
syslog_alerts.php Updates alert controls.
syslog_dashboards.php Updates dashboard controls.
syslog_device_rules.php Updates the Cancel button.
syslog_removal.php Updates removal controls.
syslog_reports.php Updates report controls.
syslog_saved_searches.php Updates saved-search controls.
js/​functions.js Adds delegated event bindings.
README.md Documents older-Cacti compatibility.
CHANGELOG.md Records the security change.

🧠 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 Outdated
Comment thread syslog_dashboards.php
}

$save_html = "<input type='button' value='" . __esc('Cancel', 'syslog') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' class='export' value='" . __esc('Continue', 'syslog') . "' title='$title'>";
$save_html = "<input type='button' value='" . __esc('Cancel', 'syslog') . "'>&nbsp;<input type='submit' class='export cactiReturnTo' value='" . __esc('Continue', 'syslog') . "' title='$title'>";
Comment thread syslog_saved_searches.php
$title = $export ? __esc('Export Saved Search Template(s)', 'syslog') : __esc('Delete Saved Search Template(s)', 'syslog');

$save_html = "<input type='button' value='" . __esc('Cancel', 'syslog') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' class='export' value='" . __esc('Continue', 'syslog') . "' title='$title'>";
$save_html = "<input type='button' value='" . __esc('Cancel', 'syslog') . "'>&nbsp;<input type='submit' class='export cactiReturnTo' value='" . __esc('Continue', 'syslog') . "' title='$title'>";
Comment thread syslog.php

if ($theme == 'classic' || read_config_option('autocomplete') > 0) {
print "<select id='" . html_escape($form_name) . "' name='" . html_escape($form_name) . "'" . $class . ($on_change != '' ? "onChange='$on_change'" : '') . '>';
print "<select id='" . html_escape($form_name) . "' name='" . html_escape($form_name) . "'" . $class . ($on_change != '' ? " class='syslogFilter' data-onchange='" . str_replace('()', '', $on_change) . "'" : '') . '>';
…1 note

The plugin's supported Cacti floor is now 1.2.29 (INFO compat), so the
CSP-safe cactiReturnTo Cancel buttons need the one-time applySkin() snippet
only on Cacti 1.2.29/1.2.30; 1.2.31+ binds the class automatically. Reword the
README compatibility note to cover that 1.2.29-1.2.31 range.

@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.

The Cancel/Continue controls are miswired in syslog_dashboard_actions(): the new cactiReturnTo class is applied to the Continue submit button, while the Cancel button loses its handler. Move the class from Continue to Cancel so Continue submits the action and Cancel returns.

@TheWitness TheWitness closed this Oct 8, 2026
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