/

CVE-2026-39948

Severity:

CRITICAL RISK

(9.8)

SQL Injection (CWE-89) in Cacti rfilter Graph Queries

CVE-2026-39948

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Database Compromise and Arbitrary SQL Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A SQL injection vulnerability in Cacti allows attacker-controlled rfilter input to be concatenated directly into RLIKE clauses without proper validation.

On instances with guest graph viewing enabled, an unauthenticated attacker can inject arbitrary SQL through graph_view.php, threatening the confidentiality, integrity, and availability of the monitoring database.

Affected context

This vulnerability occurs in Cacti deployments that expose the graph_view.php endpoint with guest graph viewing enabled and rely on rfilter-based queries to render graphs or trees. In affected versions, the rfilter request parameter is retrieved via a raw input accessor and placed directly into SQL RLIKE clauses in lib/html_graph.php and lib/html_tree.php. The issue manifests when user-supplied filter values are treated as part of the SQL expression itself, without robust validation or parameterization, allowing crafted payloads to escape the intended pattern-matching context and alter database queries.

Exploit preconditions

  • Attack surface: HTTP requests to graph_view.php on Cacti installations.
  • Required access: No authentication required when guest graph viewing is enabled.
  • Trigger point: Submission of a malicious rfilter parameter that becomes part of a RLIKE clause in SQL.
  • Why exploitation is possible: The rfilter parameter is obtained via a raw accessor (grv()) and concatenated into SQL strings without using parameterized queries or regex validation (FILTER_VALIDATE_IS_REGEX via gfrv()), permitting unbalanced quotes and other meta-characters to break out of the intended filter and inject arbitrary SQL.

Why this happens

The underlying bug maps directly to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'). Application code composes SQL statements by concatenating raw HTTP parameter values into query strings used for RLIKE operations, rather than treating user input as data bound through prepared statements or validated patterns. The use of a non-filtering accessor (grv()) bypasses the regex validation that would reject malformed patterns, allowing attackers to introduce unbalanced quotes and other control characters that modify the structure of the query. This insecure pattern—building SQL with untrusted, unnormalized input—creates a direct path for arbitrary SQL execution against the backing database.

Potential impact

  • An attacker may read sensitive configuration data or monitoring metrics stored in the database.
  • An attacker could modify or delete graph, host, and performance data, disrupting monitoring operations.
  • An attacker may create or alter user accounts and permissions, leading to broader application compromise.
  • An attacker could corrupt database tables or drop schemas, impacting availability of Cacti and dependent systems.
  • An attacker can potentially chain database access into further infrastructure attacks, depending on stored credentials and integrations.

General mitigation guidance

Effective mitigation centers on eliminating dynamic SQL construction with untrusted input and constraining how filter parameters are handled. Code paths that accept user-supplied filter values should rely on parameterized queries or prepared statements so data is bound rather than concatenated into SQL expressions. When patterns or regular expressions are required, inputs can be validated against strict whitelists or dedicated regex validators, with rejection or neutralization of unbalanced quotes and control characters. Adopting secure-by-default input accessors that enforce validation, and confining filter logic to a narrow set of supported operators, reduces the risk of injection. Additionally, designing query-building routines to separate query structure from user-provided values and limiting database privileges for the application account can limit blast radius if a flaw appears.

How teams detect issues like this

Detection commonly involves reviewing code for string-built SQL that incorporates request parameters directly, especially in filter and search functionality. Static analysis tools can flag use of raw accessors, concatenation of user input into WHERE or RLIKE clauses, and absence of parameterized queries in data-access layers. During code review, maintainers can look for helper functions that bypass validation (such as non-filtering getters) and confirm that all database interactions use prepared statements and consistent input validation. Runtime monitoring, including database query logging and application-layer anomaly detection, may surface suspicious patterns like unbalanced quotes or unexpected control characters in queries. Security policies and CI checks can enforce standardized data-access APIs and disallow ad hoc SQL assembly with untrusted input.

Sources

SourceLink
github.comgithub.com/Cacti/cacti/commit/136ae6ef0715e77bca69c0eb60781f5e17df0795
github.comgithub.com/Cacti/cacti/security/advisories/GHSA-9jqv-4cpm-vm2c

Frequently asked

questions

Exploitability is high wherever guest graph viewing is enabled, because an attacker can reach the vulnerable graph_view.php endpoint without authentication and supply crafted rfilter values from any network location that can access the web interface.

No. In affected configurations with guest graph viewing enabled, the vulnerability is reachable pre-authentication. The only requirement is network access to the Cacti web interface and the ability to send HTTP requests with controlled parameters.

The safest approach is to remove all instances of dynamic SQL string concatenation involving user input and refactor to parameterized queries. Filter-related parameters should be passed as bound variables or validated patterns via secure input accessors, ensuring that untrusted data cannot change query structure.

Future prevention relies on establishing strict data-access conventions: always use prepared statements or ORM abstractions, apply rigorous input validation for filter and search parameters, and forbid direct concatenation of request data into SQL. Coupling these coding standards with automated static analysis, code review checklists, and least-privilege database accounts helps catch injection risks early and reduces their impact.

Find out what's already
exploitable in your codebase.