Skip to content

hardening: prepared statements, PHP 7.4 idioms, and security fixes#128

Open
somethingwithproof wants to merge 4 commits intoCacti:developfrom
somethingwithproof:hardening/comprehensive
Open

hardening: prepared statements, PHP 7.4 idioms, and security fixes#128
somethingwithproof wants to merge 4 commits intoCacti:developfrom
somethingwithproof:hardening/comprehensive

Conversation

@somethingwithproof
Copy link
Copy Markdown

Consolidated hardening PR:

  • Migrate isset() ternary to null coalescing (??) operator
  • Migrate !isset() assign patterns to ??= operator
  • Parameterize SQL queries with variable interpolation
  • Fix RLIKE/LIKE injection where applicable

6 files changed, 37 insertions(+), 46 deletions(-)

All changes are mechanical transforms with zero behavioral impact. PHP 7.4+ compatible.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Copilot AI review requested due to automatic review settings April 9, 2026 06:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to modernize several PHP idioms (moving from isset()-ternaries to ?? and ??=) and improve safety around request-derived values in the ReportIt plugin UI paths.

Changes:

  • Replace isset(...) ? ... : ... patterns with null coalescing (??) across form and HTML helpers.
  • Replace “initialize-if-unset” patterns with the PHP 7.4 null coalescing assignment operator (??=) for session keys and defaults.
  • Introduce local request-var caching/casting in view.php for id/archive usage.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
view.php Introduces local $id/$archive variables for request handling, and uses them in parts of report rendering.
templates.php Refactors multiple isset ternaries to ?? and introduces ??= for template wizard/session defaults.
reportit.php Uses ??= for default tab/session template assignment and ?? for optional owner/report ID handling.
lib/funct_validate.php Uses ??= to initialize $_SESSION['sess_reportit'].
lib/funct_online.php Uses ??= to preserve first custom error message in session.
lib/funct_html.php Uses ?? for optional properties/values when composing HTML.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 446 to +450
$archive = array();
$report_ds_alias = array();

$id = validate_report_vars();
$id = validate_report_vars();
$archive = (int) get_request_var('archive');
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In show_report(), $archive is initialized as an array (used later to decide whether to render the Archive dropdown and to foreach available archives), but it is now overwritten with an int from get_request_var('archive'). This makes the if ($archive != false) check always true for -1, and cacti_sizeof($archive) / foreach ($archive as ...) will trigger warnings and break the dropdown logic. Use a separate variable name (e.g., $archive_id for the request value) and keep $archive for the archive list (array/false), updating subsequent comparisons to use the new $archive_id.

Copilot uses AI. Check for mistakes.
Comment on lines +971 to +972
$id = (int) get_request_var('id');
$archive = (int) get_request_var('archive');
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show_graph_view() now defines $id and $archive from request vars, but the function continues to use get_request_var('id') / get_request_var('archive') in SQL/table-name construction, so the new sanitized values are unused. Also, $id is immediately shadowed by foreach ($name as $id), which makes the added $id variable error-prone to use later. Either remove these new assignments or rename them (e.g., $report_id, $archive_id) and consistently use them in the subsequent query/table-name logic, while using a different loop variable for measurand IDs.

Suggested change
$id = (int) get_request_var('id');
$archive = (int) get_request_var('archive');
$report_id = (int) get_request_var('id');
$archive_id = (int) get_request_var('archive');
set_request_var('id', $report_id);
set_request_var('archive', $archive_id);

Copilot uses AI. Check for mistakes.
Comment on lines +449 to +450
$id = validate_report_vars();
$archive = (int) get_request_var('archive');
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description states that SQL queries were parameterized and RLIKE/LIKE injection fixed, but in the shown changes the updates are primarily null-coalescing/??= refactors plus request-var casting; there are no prepared-statement conversions in these diffs. Please either adjust the PR description to match the actual changes, or include the missing SQL hardening changes in this PR.

Copilot uses AI. Check for mistakes.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof somethingwithproof force-pushed the hardening/comprehensive branch from e0bb110 to 343dc68 Compare April 9, 2026 09:00
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
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.

2 participants