security: parameterize SQL in sequence functions and data_queries.php (1.2.x backport)#6911
Merged
TheWitness merged 3 commits intoCacti:1.2.xfrom Mar 29, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Hardens Cacti 1.2.x sequence/move helpers and data_queries.php by adding a safe, parameterized way to construct simple WHERE clauses and migrating select callers away from raw SQL concatenation to prepared queries to mitigate SQL injection risks.
Changes:
- Added
build_where_from_array()and extendedget_item()/get_sequence()to accept array-based filters (in addition to legacy string WHERE fragments). - Updated
get_item()/get_sequence()to use prepared DB helpers (db_fetch_cell_prepared,db_fetch_row_prepared) for safer execution. - Converted several
data_queries.phpmove-up/down callers to pass array filters instead of concatenated SQL.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
lib/functions.php |
Adds array-to-WHERE helper and updates sequence/item retrieval to use prepared queries and accept array filters. |
data_queries.php |
Switches several move-up/down calls to pass structured filters (arrays) rather than interpolated SQL. |
tests/Unit/DbLayerHardeningTest.php |
Introduces a new unit test file intended to validate the new WHERE-builder behavior. |
TheWitness
previously approved these changes
Mar 28, 2026
Member
|
This one looks correct. |
… (1.2.x backport) - Add build_where_from_array() helper for safe parameterized WHERE clauses - Update get_item() and get_sequence() to accept array filters - Convert 4 raw SQL callers in data_queries.php to use parameterized arrays - Add unit tests for DB layer hardening Addresses GHSA-w839-f83f-fj47 (Critical), GHSA-pf37-v86f-5xwp (High), GHSA-9f3h-m984-g777 (High) Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
dcf2c43 to
0ae53c3
Compare
bmfmancini
approved these changes
Mar 29, 2026
xmacan
approved these changes
Mar 29, 2026
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.
Summary
Surgical edits to current 1.2.x files. +139/-11 lines.
build_where_from_array()helper for safe parameterized WHERE clausesget_item()andget_sequence()to accept array filters (backward compatible with string)db_fetch_cell()withdb_fetch_cell_prepared()in get_itemdb_fetch_row()withdb_fetch_row_prepared()in get_sequenceSecurity
Test plan
vendor/bin/pest tests/Unit/DbLayerHardeningTest.php