Skip to content

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

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

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

Conversation

@somethingwithproof
Copy link
Copy Markdown
Contributor

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, 19 insertions(+), 12 deletions(-)

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

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
… equivalents

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 consolidates several security-hardening refactors across the WebSeer plugin, focusing on safer SQL construction, modernized PHP idioms, and reduced deserialization risk.

Changes:

  • Escapes user-provided regex filter input in list_urls() and refactors related SQL string building.
  • Updates form variable injection to use null coalescing in proxy edit flow.
  • Hardens unserialize() calls and converts contact upserts to prepared statements.

Reviewed changes

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

File Description
webseer.php Escapes rfilter and refactors RLIKE filter SQL assembly in URL listing.
webseer_proxies.php Uses null coalescing when passing optional $proxy data into inject_form_variables().
includes/functions.php Disables class instantiation during unserialize and switches contact lookup/upsert to prepared statements.

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

Comment thread webseer.php
Comment on lines +746 to +750
'display_name RLIKE ' . $rfilter . ' OR ' .
'url RLIKE ' . $rfilter . ' OR ' .
'search RLIKE ' . $rfilter . ' OR ' .
'search_maint RLIKE ' . $rfilter . ' OR ' .
'search_failed RLIKE ' . $rfilter;
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.

The RLIKE predicates are concatenated with ORs without parentheses. When $sql_where already contains an AND clause (e.g., from $statefilter), SQL operator precedence will make the filter behave like "(statefilter AND display_name RLIKE ...) OR url RLIKE ...", which can return rows outside the intended state filter. Wrap the OR-ed RLIKE block in parentheses before appending it with AND/WHERE.

Suggested change
'display_name RLIKE ' . $rfilter . ' OR ' .
'url RLIKE ' . $rfilter . ' OR ' .
'search RLIKE ' . $rfilter . ' OR ' .
'search_maint RLIKE ' . $rfilter . ' OR ' .
'search_failed RLIKE ' . $rfilter;
'(display_name RLIKE ' . $rfilter . ' OR ' .
'url RLIKE ' . $rfilter . ' OR ' .
'search RLIKE ' . $rfilter . ' OR ' .
'search_maint RLIKE ' . $rfilter . ' OR ' .
'search_failed RLIKE ' . $rfilter . ')';

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

Choose a reason for hiding this comment

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

Valid. Pre-existing issue. Will add parentheses in a follow-up.

Comment thread webseer.php
Comment on lines +744 to +746
$rfilter = db_qstr(get_request_var('rfilter'));
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') .
'display_name RLIKE ' . $rfilter . ' OR ' .
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.

The PR description/title emphasize prepared statements, but this query still injects the request value into SQL via manual quoting (db_qstr) and string concatenation. Consider switching this block to use db_fetch_assoc_prepared/db_fetch_cell_prepared with a bound parameter for the RLIKE pattern (and an accompanying $sql_params array) to align with the stated hardening approach.

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

Choose a reason for hiding this comment

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

Pre-existing pattern. The PR scope is the PHP 7.4 compat change in UrlValidator.php. SQL hardening is tracked separately.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof somethingwithproof force-pushed the hardening/comprehensive branch from 7bef544 to 2c90d56 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