Repository navigation
security: move inline event handlers to CSP-safe bindings - #152
Merged
Merged
Conversation
Cacti's Content-Security-Policy script-src-attr directive blocks inline event-handler attributes. This converts the plugin's remaining inline handlers: - Confirmation-page Cancel/Return buttons (reportit.php, templates.php) switch from onClick='cactiReturnTo(...)' to the CSP-safe cactiReturnTo class, with a data-url carrying the return target where one was passed. - The filter "rows" selects (reportit, templates, view) drop their inline onChange='applyFilter()' and are bound via change() in each page's ready block (view.php already bound #rows; reportit/templates now do too). - The template calc-syntax links (html_calc_syntax in lib/funct_html.php) drop their inline onClick=add_to_calc(...) for a reportitAddCalc class + data- calc-name attribute, bound by a delegated handler in templates.php. lib/funct_html.php is measured; a new ReportitCalcSyntaxTest exercises html_calc_syntax() so the changed line stays covered. The three web-UI entry points are added to 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.
TheWitness
requested review from
bmfmancini,
browniebraun and
xmacan
and
a balanced review from Copilot
October 7, 2026 22:09
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved event-binding and test-initialization defects block approval.
3 open findings
What changed in this PR
Updates ReportIt’s UI event handling to comply with Cacti’s Content Security Policy.
Changes:
- Replaces inline Cancel, filter, and calculation-link handlers with JavaScript bindings.
- Adds calculation-markup coverage and exempts UI entry points from patch coverage.
- Documents compatibility requirements and the security changes.
| File | Description |
|---|---|
| view.php | Removes the inline rows-change handler. |
| tests/Unit/ReportitCalcSyntaxTest.php | Adds CSP-safe calculation-markup assertions. |
| tests/bin/patch-coverage.php | Allowlists three UI entry points. |
| templates.php | Updates Cancel buttons, filters, and calculation-link bindings. |
| reportit.php | Updates Cancel buttons and filter bindings. |
| README.md | Documents the Cancel-button compatibility workaround. |
| lib/funct_html.php | Emits calculation-link classes and data attributes. |
| 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.
setup.php only defines REPORTIT_BASE_PATH at runtime inside reportit_define_constants() (realm/DB work), not on bare require, so the test errored with 'Undefined constant REPORTIT_BASE_PATH' before any assertion ran. Define the same value (dirname(__DIR__, 2) == CACTI_PATH_BASE/plugins/reportit) as a fallback, matching how PreparedStatementConsistencyTest resolves paths.
Address Copilot review on PR #152: - templates.php: the metric-editor ready block re-runs on every AJAX page load (applySkin) and binds to the persistent document, so the delegated reportitAddCalc click handler accumulated and appended a token multiple times per click after reopening the editor. Namespace the handler and off() it before on(). - README.md: the .cactiReturnTo binding lives in Cacti 1.2.x include/layout.js but the refactored 1.3.0/develop layout.js dropped it, so framing the workaround as 'below 1.2.31' left develop/1.3 users with inactive Cancel buttons. Describe the workaround by binding availability instead.
bmfmancini
approved these changes
Oct 8, 2026
bmfmancini
left a comment
Member
There was a problem hiding this comment.
Reviewed; cactiReturnTo conversion uses data-url plus the class correctly, Continue buttons still submit. Checks pass.
browniebraun
approved these changes
Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Removes the plugin'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(...)'to the CSP-safecactiReturnToclass, withdata-urlcarrying the return target when one was passed (including the concatenatedtemplates.php?tab=variables&id=...targets).onChange='applyFilter()'and bind viachange()in each page's ready block.view.phpalready bound#rows; reportit/templates now do too.html_calc_syntaxin lib/funct_html.php) — drop inlineonClick=add_to_calc(...)for areportitAddCalcclass +data-calc-nameattribute, bound by a delegated handler in templates.php (whereadd_to_calcis defined).Gate / tests
lib/funct_html.phpis a measured source file, so a new tests/Unit/ReportitCalcSyntaxTest.php exerciseshtml_calc_syntax()(seeding$calc_var_names) to keep the changed line covered. The three web-UI entry points (reportit.php, templates.php, view.php) are added to the patch-coverage allowlist. No__()/__esc()calls changed, so thecheck-i18n-pot.phpgate passes 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.