/

CVE-2026-66838

Severity:

HIGH RISK

(8.2)

SQL Injection (CWE-89) in Postgrex Stream Comments

CVE-2026-66838

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Database Query Manipulation

Severity:

HIGH RISK

(8.2)

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 Postgrex allows attacker-influenced values supplied through the :comment option of Postgrex.stream/4 to alter the streamed SQL statement. Because Ecto exposes this option through Ecto.Repo.stream/2, an attacker who can control the comment value may execute additional SQL clauses under the database connection's role.

Affected context

The issue occurs in applications using affected Postgrex releases when streamed queries accept attacker-influenced values for the :comment option. Postgrex appends this value directly to the statement text sent in the PostgreSQL Parse message, while the streaming execution path does not apply the validation used by other execution paths. The injection is confined to the streamed statement because PostgreSQL Parse accepts only one command.

Exploit preconditions

  • Attack surface: Application code that invokes Postgrex.stream/4 or Ecto.Repo.stream/2
  • Required access: Ability to influence the stream comment value, directly or through application-controlled input
  • Trigger point: Construction and parsing of the streamed SQL statement
  • Database condition: The application must have an active PostgreSQL connection with permissions granted to its configured role
  • Why exploitation is possible: The streaming path concatenates the comment into SQL text without rejecting comment terminators or applying the validation used elsewhere

Why this happens

The underlying bug is improper neutralization of special elements in an SQL command, mapping to CWE-89: SQL Injection. The streaming implementation treats a comment option as non-executable metadata but concatenates it into the statement before parsing. Because the stream path omits the existing comment validation routine, attacker-controlled text can escape the intended comment context and become part of the parsed SQL statement.

Potential impact

  • An attacker may alter the streamed query's logic
  • The application may return unauthorized database records
  • Database data may be modified or deleted if the connection role permits it
  • Sensitive information may be exposed through query results or side effects
  • Database availability may be affected by resource-intensive or disruptive clauses
  • The impact could extend to other systems reachable through database capabilities or trusted extensions

General mitigation guidance

Mitigation generally focuses on ensuring that metadata cannot become executable SQL and that all execution paths share the same validation guarantees.

Common defensive patterns include:

  • Treating comment and annotation values as untrusted input
  • Rejecting or safely encoding comment delimiters before statement construction
  • Reusing centralized validation logic for streamed and non-streamed execution paths
  • Prefering parameterized query values for data rather than interpolating input into SQL text
  • Allowing only fixed, server-generated comments where comments are not required
  • Applying least-privilege permissions to database roles used by streaming workloads
  • Separating read-only streaming connections from roles that can modify sensitive data

How teams detect issues like this

Organizations can look for this class of issue through:

  • Static analysis rules identifying string concatenation of user-controlled values into SQL statements
  • Code review checks for comment, hint, annotation, or logging options appended to query text
  • Comparisons of validation behavior across normal and streaming execution paths
  • Tests that supply boundary characters and verify that metadata remains non-executable
  • Database audit logging for unexpected clauses or operations issued by streaming roles
  • Policy enforcement requiring parameterization or approved query-construction APIs

Automated code review and taint-analysis tools may help identify flows from request or tenant input into Postgrex and Ecto query options.

Sources

SourceLink
cna.erlef.orgcna.erlef.org/cves/CVE-2026-66838.html
github.comgithub.com/elixir-ecto/ecto/security/advisories/GHSA-3gww-3f36-2388
github.comgithub.com/elixir-ecto/postgrex/commit/4011be852c99dc61ddb98cb01aa41e8775a0e3dd
github.comgithub.com/elixir-ecto/postgrex/commit/e1ecba618ddea4cee2556bd6ad9b6285e05f9d3c
osv.devosv.dev/vulnerability/EEF-CVE-2026-66838

Frequently asked

questions

It can be exploitable through an application interface when an attacker can influence the stream comment value. Direct network access to PostgreSQL is not necessarily required.

The attacker needs an input path that reaches Postgrex.stream/4 or Ecto.Repo.stream/2. The resulting operations execute with the permissions of the application's database connection role.

Ensure comment values cannot alter SQL syntax by using shared validation or safe construction logic on every execution path, including streaming queries. Parameterized values should be used for data whenever applicable.

Keep metadata separate from executable SQL, apply taint-aware review to query construction, test every query execution mode, and enforce least-privilege database roles.

Find out what's already
exploitable in your codebase.