CVE-2026-32687: SQL injection via channel name in Postgrex.Notifications.listen/3 and unlisten/3
Summary
SQL injection in Postgrex.Notifications.listen/3: the channel argument is interpolated straight into LISTEN "..." / UNLISTEN "..." without escaping the " character. Any caller that lets a user influence the channel name (e.g. a pub/sub bridge that uses a tenant id or topic slug as the channel) and the name is not sanitized can execute arbitrary SQL on the notifications connection.
Only those using the Postgrex.Notifications directly or via a dependency, with a non-sanitized channel name are vulnerable. Ecto does not use Postgrex.Notifications by default, but you must validate if any other dependency does.
Details
PostgreSQL escapes a " inside a quoted identifier by doubling it to "". Postgrex doesn't do that doubling, so a " inside channel closes the identifier early and everything after it is parsed as SQL on the same connection.
The notifications connection runs as whatever DB role the app is configured with. Unlike the Postgrex.query/4 API, there's no extended-protocol guard here: LISTEN/UNLISTEN are sent as simple queries, so multi-statement payloads work and the attacker can chain ; CREATE TABLE …, ; DROP …, ; CREATE ROLE …, etc.
Impact
SQL injection on the notifications connection. Affects any application that calls Postgrex.Notifications.listen/3 (or unlisten/3) with a channel name derived from untrusted input. Executes as the configured DB user with no protocol-level limit on what can be chained, so the realistic blast radius is read/modify/destroy on any data the app's DB role can reach.
Fix
Upgrade to latest Postgrex v0.22.2 or later. Altenratively, sanitize any user input given as channel name by making sure it doesn't include quotes as well as null bytes (not strictly required, but recommended):
elixir if String.contains?(channelname, ["\"", "\0"]) do raise "bad channel name" end
Other sources
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') vulnerability in elixir-ecto postgrex ('Elixir.Postgrex.Notifications' module) allows SQL Injection.
The channel argument passed to 'Elixir.Postgrex.Notifications':listen/3 and 'Elixir.Postgrex.Notifications':unlisten/3 is interpolated directly into LISTEN "..." / UNLISTEN "..." SQL statements without escaping the " character. An attacker who can influence the channel name can inject a " to break out of the quoted identifier and append arbitrary SQL. Because the notifications connection uses the PostgreSQL simple query protocol, multi-statement payloads are accepted, allowing DDL and DML commands to be chained (e.g. ; DROP TABLE ...; --). The same unsanitized interpolation also occurs in handleconnect/1 when replaying LISTEN commands after a reconnect.
This vulnerability is associated with program file lib/postgrex/notifications.ex and program routines 'Elixir.Postgrex.Notifications':listen/3, 'Elixir.Postgrex.Notifications':unlisten/3, 'Elixir.Postgrex.Notifications':handleconnect/1.
This issue affects postgrex: from 0.16.0 before 0.22.2, from pkg:github/elixir-ecto/postgrex@266b530faf9bde094e31e0e4ab851f933fadc0f5 before 0.22.2.
— NVD
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
erlang/postgrexto a version that resolves this vulnerability.Fixed in 0.22.2 - Upgrade
Upgrade
elixir-ecto/postgrexto a version that resolves this vulnerability.Fixed in 0.22.2 - Configuration
Before calling Postgrex.Notifications.listen/3 or unlisten/3, validate the channel name derived from untrusted input. Reject/raise if String.contains?(channel_name, ['"', '\0']) (i.e., ensure the channel name does not include quotes (") and null bytes (\0)).
Elixir.Postgrex.Notifications listen/unlisten channel name validation = reject if channel contains '"' or '\0'
Event History
Frequently Asked Questions
What is the severity of CVE-2026-32687?
CVE-2026-32687 is classified as a high-severity SQL injection vulnerability.
How do I fix CVE-2026-32687?
To fix CVE-2026-32687, upgrade Postgrex to version 0.22.2 or later.
Which versions of Postgrex are affected by CVE-2026-32687?
CVE-2026-32687 affects Postgrex versions between 0.16.0 and 0.22.2.
What can be exploited in CVE-2026-32687?
CVE-2026-32687 can be exploited via SQL injection through improper handling of the channel name argument.
Is CVE-2026-32687 part of Elixir.Ecto's functionality?
Yes, CVE-2026-32687 specifically affects the Elixir.Postgrex.Notifications module within Elixir.Ecto.