Summary
Cacti versions 1.2.30 and earlier contain a pre-authentication SQL injection vulnerability in graph_view.php due to unsafe input validation with FILTER_VALIDATE_REGEXP.
An attacker can send crafted requests to manipulate database queries before login, potentially leading to data exposure, modification, or full application compromise.
Affected context
The vulnerability occurs in Cacti's web interface, specifically within the graph_view.php functionality that handles user-supplied parameters for viewing performance graphs.
It is present when requests are processed using FILTER_VALIDATE_REGEXP without strict anchoring or sanitization, allowing attacker-controlled data to influence SQL query construction.
Deployments exposing Cacti to untrusted networks or shared environments are at higher risk, especially when the application connects to a database with broad privileges.
Exploit preconditions
- Attack surface: HTTP(S) requests to the Cacti web interface, targeting
graph_view.php. - Required access: None; exploitation can occur pre-authentication from any client able to reach the application.
- Trigger point: Processing of crafted query parameters that pass through
FILTER_VALIDATE_REGEXPand into SQL query building. - Why exploitation is possible: The regular expression validation is unanchored and insufficiently strict, so attacker-controlled input can introduce additional SQL tokens or clauses that are concatenated into dynamic queries without parameterization.
Why this happens
The underlying bug is a classic SQL injection pattern where user input is incorporated into SQL statements without proper parameterization or escaping.
Cacti relies on FILTER_VALIDATE_REGEXP for input validation, but the regex is unanchored and does not fully constrain allowable characters and patterns.
As a result, user-supplied data can alter the structure of the SQL query rather than being treated as pure data, mapping directly to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Potential impact
- An attacker may read sensitive data from Cacti's database, including configuration and monitoring information.
- An attacker may modify or delete monitoring data and configuration entries.
- An attacker could create or alter administrative accounts indirectly through the database.
- An attacker can potentially execute further attacks on the underlying system if the database user has extended privileges (e.g., file access or stored procedures).
- The monitoring environment and associated infrastructure could be misconfigured or blinded, impacting operational visibility.
General mitigation guidance
Mitigation generally focuses on eliminating dynamic SQL that directly incorporates user input and strengthening validation boundaries.
Recommended patterns include:
- Using parameterized queries or prepared statements for all database access paths, treating inputs strictly as parameters.
- Applying allowlist-based validation for request parameters, with anchored regular expressions that explicitly constrain acceptable formats.
- Segregating database privileges so the application account has minimal rights necessary for its operation.
- Introducing defensive layers such as application firewalls or query builders that make injection structurally difficult.
- Designing monitoring endpoints so that unauthenticated users have limited or no direct interaction with query-building logic.
How teams detect issues like this
Detection typically combines code-level inspection and runtime monitoring.
Approaches include:
- Static analysis rules that flag concatenated SQL strings and uses of unparameterized queries, especially in request-handling code.
- Code review practices that require anchored, allowlist-style regular expressions and prohibit trusting regex validation alone for SQL safety.
- Security testing (e.g., dynamic application security testing) that attempts standard SQL injection payloads against unauthenticated endpoints like
graph_view.php. - Logging and anomaly detection for unusual query patterns or errors emanating from the database when handling web requests.
- Policy enforcement in CI/CD pipelines ensuring all new data-access code uses parameterization and approved validation utilities.

