-
Notifications
You must be signed in to change notification settings - Fork 18
Description
SUMMARY
The current Syslog alert and removal rule engine supports an 'sql' type that allows administrators to input raw SQL fragments directly into a text box. These fragments are stored in syslog_alert.message or syslog_remove.message and later concatenated into poller queries within functions.php (e.g., syslog_get_alert_sql, syslog_remove_items).
Existing pattern:
- Fetch rule from DB.
- If type is 'sql', directly embed
messagestring into a WHERE clause. - Execute via
syslog_db_fetch_assocorsyslog_db_execute.
WHY REFACTOR
The existing design creates a significant second-order SQL injection risk. While the input is restricted to administrators, any compromise of an admin account or accidental entry of malformed SQL can lead to database exposure or poller failure. Furthermore, it prevents full parameterization of the core processing loop.
PROPOSED CHANGE
Introduce a namespaced QueryBuilder engine (Cacti\Syslog\QueryBuilder) that:
- Accepts a structured JSON payload representing filtering logic (field, operator, value).
- Validates fields against a strict allow-list.
- Generates a fully parameterized SQL string and a corresponding array of bound parameters.
- Provides a deprecated fallback for legacy raw SQL rules to ensure a migration path.
SCOPE
- Implementation of
src/QueryBuilder.php. - Integration into
functions.phpfor alert and removal processing. - Addition of unit tests in
tests/Unit/QueryBuilderTest.phpusing Pest. - Behavior-preserving for legacy rules while enabling secure JSON-based rules.