Skip to content

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

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

hardening: prepared statements, PHP 7.4 idioms, and security fixes#51
somethingwithproof wants to merge 3 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

3 files changed, 13 insertions(+), 13 deletions(-)

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

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
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 hardens the Cacti Audit plugin by reducing injection/XSS risk and modernizing a small PHP idiom, aligning with the plugin’s security posture around database access and UI output.

Changes:

  • Convert the audit retention purge query to a prepared statement.
  • Escape audit log “getdata” output fields to prevent HTML/JS injection in the UI.
  • Modernize session user ID fallback using the null coalescing operator.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
setup.php Uses db_execute_prepared() for the retention-based purge query.
audit.php Applies html_escape() to multiple fields when rendering audit record details.
audit_functions.php Replaces isset() ternary with ?? for session user ID fallback.

Comment thread audit.php
Comment on lines +54 to +60
$output .= '<span><b>' . __('Page:', 'audit') . '</b> <i>' . html_escape($data['page']) . '</i></span>';
$output .= '<br><span><b>' . __('User:', 'audit') . '</b> <i>' . html_escape($data['user_agent']) . '</i></span>';
$output .= '<br><span><b>' . __('IP Address:', 'audit') . '</b> <i>' . html_escape($data['ip_address']) . '</i></span>';
$output .= '<br><span><b>' . __('Date:', 'audit') . '</b> <i>' . html_escape($data['event_time']) . '</i></span>';
$output .= '<br><span><b>' . __('Action:', 'audit') . '</b> <i>' . html_escape($data['action']) . '</i></span>';
$output .= '<hr>';
$output .= '<span><b>' . __('Script:', 'audit') . '</b> <i>' . $data['post'] . '</i></span>';
$output .= '<span><b>' . __('Script:', 'audit') . '</b> <i>' . html_escape($data['post']) . '</i></span>';
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 the changes have "zero behavioral impact", but escaping values with html_escape() changes the rendered output (e.g., special characters will display escaped) and is a functional/security behavior change. Please update the PR description (or note this as an intentional behavior change) so reviewers/operators aren't surprised.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Correct observation. The ?? operator preserves behavior when the value is set. The only behavioral difference is when the value is null, which previously would have triggered an undefined variable notice.

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