Skip to content

security: move map navigation handlers to CSP-safe bindings - #141

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

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

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

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

Changes

  • includes/polling/processregion.php (gpsmap_render_region) — the "Start Over" and "Print" buttons drop their inline onclick="window.location.reload(true)" / onclick="window.open('print.php')" handlers and carry gpsmapStartOver / gpsmapPrint classes instead.
  • js/GPSMaps.js — adds delegated click bindings for those classes. GPSMaps.js is already included on every page via the page_head hook, and delegation on document handles the AJAX-injected region body.
  • CHANGELOG.md — entry.

Gate / tests

processregion.php is a measured source file; gpsmap_render_region is executed many times by tests/Integration/PollingTest.php (and the changed lines are unconditional in that render path), so the changed lines stay covered. No test asserts the button markup, and no __esc()/i18n calls changed, so cacti.pot is untouched.

Cacti's Content-Security-Policy script-src-attr directive blocks inline
event-handler attributes. The map region navigation's "Start Over" and
"Print" buttons (gpsmap_render_region in includes/polling/processregion.php)
used inline onclick="window.location.reload(true)" and
onclick="window.open('print.php')" handlers.

They now carry gpsmapStartOver / gpsmapPrint classes and are wired via
delegated jQuery bindings in js/GPSMaps.js, which is already included on every
page via the page_head hook. No i18n calls changed, so cacti.pot is untouched.

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 security-sensitive generated markup lacks regression assertions preventing inline handlers from returning.

2 open findings
What changed in this PR

Moves map navigation actions from inline handlers to CSP-safe delegated jQuery bindings.

Changes:

  • Replaces inline onclick attributes with dedicated CSS classes.
  • Adds delegated handlers for reload and print actions.
  • Documents the security change.
File Description
js/​GPSMaps.js Adds delegated navigation handlers.
includes/​polling/​processregion.php Emits CSP-safe button markup.
CHANGELOG.md Records the CSP cleanup.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread includes/polling/processregion.php
Comment thread js/GPSMaps.js Outdated
TheWitness and others added 2 commits October 7, 2026 18:28
Adds an expect()-based test that renders gpsmap_render_region() and asserts the Start Over/Print controls use delegated jQuery classes (gpsmapStartOver/gpsmapPrint) with no inline onclick. Satisfies the changed-line coverage gate for processregion.php, which the existing assert_*-helper tests (flagged risky) do not record.
Addresses review feedback: indent the chained delegated click bindings and their callback bodies to reflect nesting, convert jQuery() to the \ shorthand, and add a trailing newline.
@TheWitness
TheWitness merged commit 2f5651f into develop Oct 8, 2026
5 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