/

CVE-2026-34400

Severity:

CRITICAL RISK

(9.8)

SQL Injection in Alerta Query String Search API

CVE-2026-34400

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Arbitrary SQL Execution / Database Compromise

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

The Alerta monitoring tool contained an SQL injection vulnerability in its query string search API parameter (q=), where user-supplied search terms were directly interpolated into SQL WHERE clauses using f-strings.

Under conditions where an attacker can control the q parameter, this flaw can allow arbitrary SQL execution against the backing PostgreSQL database, potentially leading to data exfiltration, tampering, or complete compromise of monitoring data.

Affected context

This vulnerability appears when Alerta is deployed with a PostgreSQL backend and the query string search API is exposed to users or integrated systems.

The affected code path builds WHERE clauses by directly embedding the q parameter into SQL strings via Python f-strings, instead of using parameterized queries or a safe query builder.

Risk is higher in environments where untrusted users, external clients, or automation can set arbitrary values in the q parameter, especially on internet-facing instances or multi-tenant deployments.

Exploit preconditions

  • Attack surface: HTTP(S) API endpoint that accepts a q query string parameter for searching.
  • Required access: Ability to send requests to the Alerta API (typically network access; authentication requirements depend on configuration).
  • Trigger point: Submission of crafted q values that alter the intended SQL WHERE clause.
  • Why exploitation is possible: The application constructs SQL using string interpolation (f-strings) with unvalidated, unparameterized user input, allowing attackers to break out of the intended query structure and inject arbitrary SQL expressions.

Why this happens

The underlying bug stems from building SQL queries through direct string concatenation and interpolation using f-strings instead of using bound parameters.

This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where user-controlled data is inserted into SQL commands without adequate escaping or parameterization.

Because the PostgreSQL query parser receives attacker-controlled fragments as part of the SQL syntax, it interprets them as executable SQL rather than pure data, enabling modification of the query logic and execution of unintended commands.

Potential impact

  • Attackers may read sensitive monitoring data and metadata from the underlying PostgreSQL database.
  • Malicious users could modify or delete alerts, events, or configuration records, impacting monitoring integrity.
  • SQL injection can be used to escalate privileges at the application level by manipulating user or token records, where present.
  • In certain configurations, attackers could leverage database features to execute server-side functions, possibly aiding further lateral movement.

General mitigation guidance

Effective mitigation focuses on eliminating unsafe query construction and reducing trust in user-supplied search expressions:

  • Replace f-string or string-concatenated SQL with parameterized queries or an ORM/query builder that separates code from data.
  • Introduce a structured search DSL or whitelist-based filtering that maps allowed q fields and operators to safe query fragments.
  • Normalize and validate q input strictly, rejecting unexpected characters, operators, or patterns rather than attempting to sanitize them in-place.
  • Apply least-privilege to the database user used by Alerta so that, even if a query is abused, capabilities like schema changes or superuser-level operations are not possible.
  • Design APIs such that complex search capabilities are implemented server-side, minimizing the need to pass raw query syntax directly from clients.

How teams detect issues like this

Organizations can detect and monitor for similar issues using a combination of code-centric and operational approaches:

  • Static analysis: Configure SAST tools or linters to flag dynamic SQL built via f-strings, string concatenation, or format operations that include request parameters.
  • Code review: During reviews, treat any raw SQL construction as high-risk; require use of parameter binding and explicit mapping from request parameters to query fields.
  • Security testing: Incorporate SQL injection test cases into API security tests and regression suites, using automated scanners or fuzzers focused on query parameters like q.
  • Runtime monitoring: Analyze database logs for anomalous queries containing unexpected keywords or comment markers that may indicate injection attempts, and correlate with API access logs.

Sources

SourceLink
github.comgithub.com/alerta/alerta/commit/aeba85a37a09e5769a7a2da56481aa979ff99a00
github.comgithub.com/alerta/alerta/commit/fdd52cd1abad8d02d1dfb8ecdcdbb43b6af3b883
github.comgithub.com/alerta/alerta/pull/2040
github.comgithub.com/alerta/alerta/pull/712
github.comgithub.com/alerta/alerta/releases/tag/v9.1.0
github.comgithub.com/alerta/alerta/security/advisories/GHSA-8prr-286p-4w7j

Frequently asked

questions

Yes, it can be remotely exploitable if the Alerta API is exposed over the network and attackers can send requests that control the q query parameter, subject to whatever authentication or access controls the deployment enforces.

An attacker needs the ability to call the affected search API endpoint with attacker-controlled q values. In some deployments this may require valid API credentials; in others, the endpoint may be more broadly accessible.

The most robust fix is to remove all dynamic string-based SQL construction that includes user input and replace it with parameterized queries or a safe query-building abstraction, combined with strong validation and whitelisting of allowed fields and operators.

Establish development standards that forbid concatenating or interpolating user input into SQL, enforce these standards through code review and automated checks, and provide secure helper APIs for building queries. Complement this with regular security testing focused on injection vectors across all exposed endpoints.

Find out what's already
exploitable in your codebase.