Postgrex
SQL injection via channel name in Postgrex.Notifications.listen/3 and unlisten/3
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') vulnerability in elixir-ecto postgrex (Postgrex.Notifications module) allows SQL Injection. The channel argument passed to Postgrex.Notifications.listen/3 and 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 handle_connect/1 when replaying LISTEN commands after a reconnect. This vulnerability is associated with program file lib/postgrex/notifications.ex and program routines Postgrex.Notifications.listen/3, Postgrex.Notifications.unlisten/3, Postgrex.Notifications.handle_connect/1. This issue affects postgrex: from 0.16.0 before 0.22.2.
Affected versions and mitigation
From the CVE record and the vendor's references.Affected
- >= 0.16.0, < 0.22.2
Fixed in 0.22.2
- >= 266b530faf9bde094e31e0e4ab851f933fadc0f5, < 7cdedbd4316bb65f82e6a9a4f922c0ac491cb770
Fixed in 7cdedbd4316bb65f82e6a9a4f922c0ac491cb770
Mitigation
Upgrade postgrex to 0.22.2 or later.
Upgrade postgrex to 7cdedbd4316bb65f82e6a9a4f922c0ac491cb770 or later.
References
Timeline
Days relative to CVE publicationNo public PoC found yet; not in CISA KEV.
PoC repositories
Found on GitHub.No PoC repositories found yet.