Skip to content

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

Merged
TheWitness merged 4 commits into
developfrom
fix/csp-inline-handlers
Oct 8, 2026
Merged

TheWitness merged 4 commits into
developfrom
fix/csp-inline-handlers

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

Removes the plugin'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 buttons (flowview_databases.php, flowview_filters.php, flowview_schedules.php) — onClick='cactiReturnTo()' → cactiReturnTo class. flowview_devices.php — onClick='document.location="flowview_devices.php"' → cactiReturnTo class + data-url.
  • Database page selects (#source/#rows/#verified/#version) — drop inline onChange='applyFilter()', bound via change() in each of the three ready blocks.
  • Main filter (flowview_display_filter in includes/functions.php) — the report/sort/cutoff selects, the predefined-timespan select, and the time-shift icons drop their inline onChange/onclick and are bound in the function's own ready block via delegated change()/click() calls to the same applyFilter/applyTimespan/timeshiftFilterLeft/Right functions they already invoked.

Gate / tests

includes/functions.php is measured; the time-shift <i> lines carry a <?php> so they count. A new tests/Unit/FlowviewFilterControlsTest.php renders flowview_display_filter() to keep those lines covered. The web-UI entry points are 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 the plugin's remaining inline handlers:

- Confirmation Cancel buttons (flowview_databases.php, flowview_filters.php,
  flowview_schedules.php) switch from onClick='cactiReturnTo()' to the
  cactiReturnTo class; flowview_devices.php's Cancel button drops its
  onClick='document.location=...' for the cactiReturnTo class + data-url.
- The database page's source/rows/verified/version selects drop inline
  onChange='applyFilter()' and are bound via change() in each ready block.
- The main filter's report/sort/cutoff selects, the predefined-timespan select
  and the time-shift icons (flowview_display_filter in includes/functions.php)
  drop their inline onChange/onclick and are bound in the function's ready
  block via delegated change()/click() calls to the same applyFilter/
  applyTimespan/timeshift functions they already used.

includes/functions.php is measured; a new FlowviewFilterControlsTest exercises
flowview_display_filter() so the changed time-shift lines stay covered. The web
UI entry points 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

The new test cannot load its target function, and supported Cacti 1.2.29–1.2.30 installations receive inert Cancel buttons without a core patch.

3 open findings
What changed in this PR

Moves inline event handlers to CSP-safe JavaScript bindings across FlowView.

Changes:

  • Rebinds filter controls and time-shift actions through JavaScript.
  • Converts Cancel buttons to cactiReturnTo.
  • Adds compatibility documentation, tests, and changelog entry.
File Description
CHANGELOG.md Records the CSP cleanup.
README.md Documents pre-1.2.31 compatibility steps.
includes/​functions.php Rebinds main filter controls.
flowview_databases.php Rebinds database filters and Cancel action.
flowview_devices.php Converts the Cancel action.
flowview_filters.php Converts the Cancel action.
flowview_schedules.php Converts the Cancel action.
tests/​Unit/​FlowviewFilterControlsTest.php Adds filter-control regression coverage.

🧠 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
Comment thread tests/Unit/FlowviewFilterControlsTest.php Outdated
Comment thread tests/Unit/FlowviewFilterControlsTest.php Outdated
TheWitness and others added 3 commits October 7, 2026 18:54
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…shift controls

flowview_display_filter() requires includes/arrays.php, which re-keys its device/template lookups with Cacti core's array_rekey(). The stub test bootstrap does not define it, so the require threw 'Call to undefined function array_rekey()' before any markup was emitted and the timeshiftBackward/Forward assertions saw empty output. Add a function_exists-guarded array_rekey stub mirroring core behaviour.

@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; CSP-safe bindings look correct (Cancel uses cactiReturnTo class, Continue still submits). Checks pass.

@TheWitness
TheWitness merged commit c733210 into develop Oct 8, 2026
3 checks passed
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