hardening: migrate audit SQL helpers to prepared variants#49
hardening: migrate audit SQL helpers to prepared variants#49somethingwithproof wants to merge 3 commits intoCacti:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the audit plugin by migrating remaining dynamic SQL helper call sites in runtime and setup paths to prepared-statement variants, reducing SQL injection risk while keeping existing UI behavior intact.
Changes:
- Convert
setup.phpplugin-config reads/updates and retention purge delete to prepared DB helpers. - Convert
audit.phpfilter/list/export queries to prepared DB helpers using a sharedaudit_build_filter_sql()where/params builder. - Add a lightweight regression script to assert the prepared-helper migrations remain in place.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
audit.php |
Reworks filter SQL building and converts log list/export queries to prepared DB helpers. |
setup.php |
Converts version/config updates and retention purge delete to prepared DB helpers. |
tests/test_prepared_statements.php |
Adds regex-based regression checks to guard against reintroducing raw DB helpers. |
You can also share your feedback on Copilot code review. Take the survey.
| if ($class == 'all') { | ||
| if (!db_table_exists('alert_log', false, $rcnn_id)) { | ||
| $create = db_fetch_cell('SHOW CREATE TABLE autid_log'); | ||
| $create = db_fetch_cell_prepared('SHOW CREATE TABLE autid_log', array()); | ||
|
|
||
| db_execute($create, false, $rcnn_id); |
There was a problem hiding this comment.
Great catch. Fixed in 0a07152: corrected the dependency check to audit_log and aligned SHOW CREATE TABLE audit_log to the actual plugin schema. Also added regression coverage in tests/test_prepared_statements.php.
|
Incorporated follow-up review feedback in |
Summary
plugin_auditSQL helper call sites to prepared variantsaudit.phpto prepared helper usageaudit_build_filter_sql()where/param buildersetup.phpto prepared variantsTests
php -l audit.phpphp -l setup.phpphp -l tests/test_prepared_statements.phpphp tests/test_prepared_statements.phpCloses #48