/

CVE-2026-32687

Severity:

HIGH RISK

(7.8)

SQL Injection in Elixir.Postgrex.Notifications Channel

CVE-2026-32687

Modified

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Arbitrary SQL Execution in Backend Database

Severity:

HIGH RISK

(7.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 flaw in the Elixir.Postgrex.Notifications module allows attacker-controlled channel names to be interpolated directly into PostgreSQL LISTEN and UNLISTEN statements without proper escaping of quotes.

When an application lets untrusted input influence notification channel names, an attacker can craft payloads that break out of the quoted identifier and execute arbitrary SQL, including multi-statement DDL and DML commands, over the PostgreSQL simple query protocol.

Affected context

This vulnerability appears in Elixir applications that use the postgrex library's Elixir.Postgrex.Notifications module to subscribe to PostgreSQL notification channels.

It becomes relevant when:

  • Notification channels are constructed from dynamic values, especially user-controlled or externally influenced data.
  • listen/3 and unlisten/3 are invoked with channel names that are not validated, escaped, or constrained to safe patterns.
  • The notification connection uses PostgreSQL's simple query protocol, which accepts multi-statement SQL payloads.

The same unsafe interpolation occurs when reconnect logic replays LISTEN commands in handle_connect/1, so risks persist across connection resets.

Exploit preconditions

  • Attack surface: Application features that derive PostgreSQL notification channel names from request parameters, headers, message payloads, tenant identifiers, or other untrusted sources.
  • Required access: Ability to influence or control the string passed as the channel argument to Postgrex.Notifications.listen/3 or unlisten/3 (directly or via higher-level abstractions that wrap these APIs).
  • Trigger point: Execution of a LISTEN or UNLISTEN operation on the notifications connection, including automatic re-subscription during handle_connect/1 after reconnect.
  • Why exploitation is possible: The channel value is interpolated directly into SQL LISTEN "..." / UNLISTEN "..." without escaping the " character, allowing an attacker to close the quoted identifier and append arbitrary SQL. Because the connection uses the PostgreSQL simple query protocol, the backend accepts chained statements separated by semicolons.

Why this happens

The underlying bug is an instance of CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').

Instead of using parameterized queries or a dedicated identifier-quoting routine, the Elixir.Postgrex.Notifications implementation constructs LISTEN and UNLISTEN statements by string interpolation, embedding the channel value directly between double quotes.

No escaping is applied to the " character, so crafted channel names can terminate the quoted identifier context and inject additional SQL tokens, operators, and statements.

Because the notifications connection relies on PostgreSQL's simple query protocol, the database executes every statement in the constructed string, turning what should be a metadata subscription operation into a general-purpose SQL execution vector.

Potential impact

  • Arbitrary SQL commands may be executed on the backend database within the privileges of the notifications connection.
  • Attackers could perform destructive operations, such as DROP TABLE or TRUNCATE, leading to loss of critical data.
  • Data manipulation (INSERT, UPDATE, DELETE) could be used to corrupt application state, tamper with business records, or escalate logical privileges.
  • Sensitive data could be exfiltrated if the attacking context can observe query results or use injected SQL to influence subsequent application flows.
  • Compromised database integrity can undermine audit trails, reporting accuracy, and downstream analytics.

General mitigation guidance

Effective mitigation focuses on preventing untrusted input from being directly incorporated into SQL, especially for identifiers such as channel names.

Pattern-based hardening approaches include:

  • Strict input constraints: Treat notification channel names as configuration or internal identifiers where possible. If they must be dynamic, restrict them to a conservative character set (e.g., alphanumerics, underscores) and validate against a strict pattern before use.
  • Safe construction of SQL identifiers: Use library-provided mechanisms or well-reviewed helper functions for safely quoting identifiers, rather than manual string concatenation. Separate data from SQL structure whenever possible.
  • Abstraction boundaries: Encapsulate LISTEN/UNLISTEN invocations in a small, well-audited module that never accepts raw external input as a channel name.
  • Privilege minimization: Run the notifications connection under a database role with least privilege—able to LISTEN/UNLISTEN on needed channels but restricted from dangerous DDL/DML operations. This reduces blast radius if injection occurs.
  • Configuration hardening: Where feasible, keep channel names static or environment-configured rather than request-derived, so they remain outside user control.

How teams detect issues like this

Detection efforts can focus on both code patterns and runtime behavior:

  • Static analysis: Configure SAST rules or custom linters for Elixir/Erlang projects to flag string interpolation in SQL statement construction, especially around LISTEN, UNLISTEN, and other meta-commands. Look for concatenation of variables into SQL snippets rather than parameterization.
  • Code review signals: During manual reviews, pay special attention to:
  • Direct use of untrusted input in Postgrex.Notifications.listen/3 and unlisten/3.
  • Helper functions that build channel names from request data or user identifiers.
  • Any reconnection logic that replays LISTEN statements by reconstructing SQL from in-memory state.
  • Policy enforcement: Adopt coding standards that disallow raw SQL string construction for control statements where parameters are not supported, and mandate validated, whitelisted identifiers for notification channels.
  • Runtime and log analysis: Monitor database logs for unexpected LISTEN/UNLISTEN patterns, suspicious multi-statement queries initiated from notification connections, or DDL statements executed by roles intended only for listening.

Sources

SourceLink
cna.erlef.orgcna.erlef.org/cves/CVE-2026-32687.html
github.comgithub.com/elixir-ecto/ecto/security/advisories/GHSA-r73h-97w8-m54h
github.comgithub.com/elixir-ecto/postgrex/commit/7cdedbd4316bb65f82e6a9a4f922c0ac491cb770
osv.devosv.dev/vulnerability/EEF-CVE-2026-32687

Frequently asked

questions

It can be, if a remote user can influence the channel name used by Postgrex.Notifications. Any API or feature that maps user input directly or indirectly into notification channel names can form a remote entry point for injection.

The attacker needs the ability to control or meaningfully influence the channel argument passed to listen/3 or unlisten/3. This might be through web requests, message payloads, configuration endpoints, or multi-tenant naming schemes that build channel names from user-supplied identifiers.

The general fix is to eliminate raw interpolation of channel names into SQL and ensure that only validated, constrained identifiers are used. This typically means validating channel names against a strict whitelist pattern, centralizing channel management, and using safe quoting or parameterization patterns where supported.

To prevent similar problems, treat any value that reaches SQL as untrusted by default, enforce parameterization for all data values, use strict validation for identifiers, and adopt secure coding guidelines for database access layers. Incorporating static analysis checks and targeted code review practices around SQL construction helps catch injection patterns early in development.

Find out what's already
exploitable in your codebase.