Skip to content

hardening: migrate quicktree SQL helpers to prepared variants#12

Open
somethingwithproof wants to merge 3 commits intoCacti:mainfrom
somethingwithproof:fix/prepared-sql-11
Open

hardening: migrate quicktree SQL helpers to prepared variants#12
somethingwithproof wants to merge 3 commits intoCacti:mainfrom
somethingwithproof:fix/prepared-sql-11

Conversation

@somethingwithproof
Copy link

Summary

  • migrate selected plugin_quicktree SQL helper reads to prepared variants
  • convert graph-tree list and max-sequence lookups in quicktree.php to prepared helpers
  • convert plugin version lookup in setup.php to prepared helper
  • preserve behavior with safe mechanical conversions

Tests

  • php -l quicktree.php
  • php -l setup.php
  • php -l tests/test_prepared_statements.php
  • php tests/test_prepared_statements.php

Closes #11

Copilot AI review requested due to automatic review settings March 15, 2026 23:28
Copy link

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 plugin_quicktree plugin by migrating selected SQL read helpers from raw query helpers to prepared-statement variants, and adds a small regression script to verify the migration patterns remain in place.

Changes:

  • Convert quicktree.php graph-tree list and max-sequence lookups to db_fetch_*_prepared.
  • Convert setup.php plugin version lookup to db_fetch_cell_prepared.
  • Add tests/test_prepared_statements.php to statically verify prepared-helper usage and absence of raw helper calls in the touched files.

Reviewed changes

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

File Description
quicktree.php Replaces specific raw read queries with prepared helper equivalents.
setup.php Uses prepared helper for plugin version lookup during upgrade checks.
tests/test_prepared_statements.php Adds regression checks (via regex) to enforce prepared-helper usage in updated files.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +28 to +29
$quicktree_contents = file_get_contents(__DIR__ . '/../quicktree.php');
$setup_contents = file_get_contents(__DIR__ . '/../setup.php');
Copy link
Author

Choose a reason for hiding this comment

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

Good call — fixed in 98b88bf. Added explicit readability assertions for both files and only then run regex checks.

Comment on lines +31 to +46
assert_true(
'quicktree.php uses prepared graph tree list query',
preg_match('/db_fetch_assoc_prepared\s*\(\s*\'SELECT g\.id,\s*g\.name\s+FROM graph_tree/s', $quicktree_contents) === 1
);
assert_true(
'quicktree.php uses prepared max sequence query',
preg_match('/db_fetch_cell_prepared\s*\(\s*\'SELECT MAX\(sequence\)\s+FROM graph_tree/s', $quicktree_contents) === 1
);
assert_true(
'quicktree.php has no raw db_fetch_assoc calls',
preg_match('/\bdb_fetch_assoc\s*\(/', $quicktree_contents) === 0
);
assert_true(
'setup.php uses prepared plugin version lookup',
preg_match('/db_fetch_cell_prepared\s*\(\s*\'SELECT version\s+FROM plugin_config\s+WHERE directory = \?/s', $setup_contents) === 1
);
Copy link
Author

Choose a reason for hiding this comment

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

Addressed in 98b88bf: de-brittled SQL assertions to check prepared helper usage plus key query tokens (graph_tree, MAX(sequence), plugin_config, directory = ?) instead of exact SQL text/quoting.

@somethingwithproof somethingwithproof changed the title security: migrate quicktree SQL helpers to prepared variants hardening: migrate quicktree SQL helpers to prepared variants Mar 15, 2026
@somethingwithproof
Copy link
Author

somethingwithproof commented Mar 16, 2026

Incorporated follow-up review feedback in 3697e04. Added follow-up workflow checks for prepared queue fetch/cleanup and parameterized existing-tree branch lookup.

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.

hardening: migrate quicktree SQL helpers to prepared variants

2 participants