hardening: prepared statements, PHP 7.4 idioms, and security fixes#128
hardening: prepared statements, PHP 7.4 idioms, and security fixes#128somethingwithproof wants to merge 4 commits intoCacti:developfrom
Conversation
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
There was a problem hiding this comment.
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.phpforid/archiveusage.
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.
| $archive = array(); | ||
| $report_ds_alias = array(); | ||
|
|
||
| $id = validate_report_vars(); | ||
| $id = validate_report_vars(); | ||
| $archive = (int) get_request_var('archive'); |
There was a problem hiding this comment.
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.
| $id = (int) get_request_var('id'); | ||
| $archive = (int) get_request_var('archive'); |
There was a problem hiding this comment.
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.
| $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); |
| $id = validate_report_vars(); | ||
| $archive = (int) get_request_var('archive'); |
There was a problem hiding this comment.
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.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
e0bb110 to
343dc68
Compare
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Consolidated hardening PR:
6 files changed, 37 insertions(+), 46 deletions(-)
All changes are mechanical transforms with zero behavioral impact. PHP 7.4+ compatible.