fix(sql): migrate interpolated queries to prepared statements#210
Closed
somethingwithproof wants to merge 1 commit intoCacti:developfrom
Closed
fix(sql): migrate interpolated queries to prepared statements#210somethingwithproof wants to merge 1 commit intoCacti:developfrom
somethingwithproof wants to merge 1 commit intoCacti:developfrom
Conversation
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR continues the plugin’s SQL-hardening effort by migrating remaining variable-interpolated DELETE queries to prepared-statement variants, reducing SQL injection risk in device-removal cleanup code.
Changes:
- Replaced interpolated
DELETE ... IN(...)queries withdb_execute_prepared(...)calls. - Added dynamic placeholder generation (
?, ?, ...) and sanitized device IDs viaintvalbefore binding.
Comment on lines
+322
to
+324
| db_execute_prepared('DELETE FROM plugin_monitor_notify_history WHERE host_id IN(' . implode(',', array_fill(0, cacti_count($devices), '?')) . ')', array_values(array_map('intval', $devices))); | ||
| db_execute_prepared('DELETE FROM plugin_monitor_reboot_history WHERE host_id IN(' . implode(',', array_fill(0, cacti_count($devices), '?')) . ')', array_values(array_map('intval', $devices))); | ||
| db_execute_prepared('DELETE FROM plugin_monitor_uptime WHERE host_id IN(' . implode(',', array_fill(0, cacti_count($devices), '?')) . ')', array_values(array_map('intval', $devices))); |
There was a problem hiding this comment.
These three DELETEs duplicate the same placeholder and parameter list construction. Consider computing $deviceIds once (sanitized/reindexed) and deriving the IN placeholder string from that array, then reuse for all three queries; it reduces repetition and avoids any risk of placeholder/param count drift if the sanitization logic changes.
Author
There was a problem hiding this comment.
Valid DRY opportunity. Will extract to a helper in a follow-up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrate remaining non-prepared SQL queries that interpolate PHP variables to use prepared statement variants (db_execute_prepared, db_fetch_cell_prepared, etc.). Static SQL without variable interpolation is left as-is.