Repository navigation
security: move inline event handlers to CSP-safe bindings - #392
TheWitness wants to merge 2 commits into
Conversation
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.
There was a problem hiding this comment.
🟡 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.
| } | ||
|
|
||
| $save_html = "<input type='button' value='" . __esc('Cancel', 'syslog') . "' onClick='cactiReturnTo()'> <input type='submit' class='export' value='" . __esc('Continue', 'syslog') . "' title='$title'>"; | ||
| $save_html = "<input type='button' value='" . __esc('Cancel', 'syslog') . "'> <input type='submit' class='export cactiReturnTo' value='" . __esc('Continue', 'syslog') . "' title='$title'>"; |
| $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()'> <input type='submit' class='export' value='" . __esc('Continue', 'syslog') . "' title='$title'>"; | ||
| $save_html = "<input type='button' value='" . __esc('Cancel', 'syslog') . "'> <input type='submit' class='export cactiReturnTo' value='" . __esc('Continue', 'syslog') . "' title='$title'>"; |
|
|
||
| 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
left a comment
There was a problem hiding this comment.
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.


Summary
Removes syslog'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.Changes
onClick='cactiReturnTo()'→cactiReturnToclass.syslog_form_callback-generated program select) — drop inlineonChange='applyFilterX()'for asyslogFilterclass +data-onchangeattribute naming the function. A single delegated handler in js/functions.js readsdata-onchangeand calls that function, so each page keeps its ownapplyFilter/applyFilterAlerts/applyFilterRemoval/applyFilterReports/applyFilterDashboards/applyFilterSavedSearchesbehaviour.onclick→ delegated#syslog_search_toggleclick binding.Gate / i18n
All changed pages are already in the patch-coverage allowlist (no measured handlers touched). 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.