CVE-2024-27289
JSON

8.1high

pgx SQL Injection via Line Comment Creation

Severity
8.1high CVSS:3.1 by GitHub_M
Exploit likelihood
0.85% (higher than 59% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-m7wr-2xf7-cm9pGO-2024-2605

Description

pgx is a PostgreSQL driver and toolkit for Go. Prior to version 4.18.2, SQL injection can occur when all of the following conditions are met: the non-default simple protocol is used; a placeholder for a numeric value must be immediately preceded by a minus; there must be a second placeholder for a string value after the first placeholder; both must be on the same line; and both parameter values must be user-controlled. The problem is resolved in v4.18.2. As a workaround, do not use the simple protocol or do not place a minus directly before a placeholder.

Affected

Product or packageVersionsReported by
jackc pgx< 4.18.2, before 4.18.2CVE List, NVD
github.com/jackc/pgx (Go)before 4.18.2, all versionsGitHub Advisory Database, Go Vulnerability Database
github.com/jackc/pgx/v4 (Go)before 4.18.2GitHub Advisory Database, Go Vulnerability Database

All scores

GitHub_M8.1high CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
GitHub8.1high CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
GitHubhigh CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N

Classification

CWE-89

SSVC (CISA-ADP): exploitation poc, automatable no, technical impact total.

What each source says

CVE List

pgx is a PostgreSQL driver and toolkit for Go. Prior to version 4.18.2, SQL injection can occur when all of the following conditions are met: the non-default simple protocol is used; a placeholder for a numeric value must be immediately preceded by a minus; there must be a second placeholder for a string value after the first placeholder; both must be on the same line; and both parameter values must be user-controlled. The problem is resolved in v4.18.2. As a workaround, do not use the simple protocol or do not place a minus directly before a placeholder.

GitHub Advisory Database
Impact

SQL injection can occur when all of the following conditions are met:

  1. The non-default simple protocol is used.
  2. A placeholder for a numeric value must be immediately preceded by a minus.
  3. There must be a second placeholder for a string value after the first placeholder; both must be on the same line.
  4. Both parameter values must be user-controlled.

e.g.

Simple mode must be enabled:

// connection string includes "prefer_simple_protocol=true"
// or
// directly enabled in code
config.ConnConfig.PreferSimpleProtocol = true

Parameterized query:

SELECT * FROM example WHERE result=-$1 OR name=$2;

Parameter values:

$1 => -42 $2 => "foo\n 1 AND 1=0 UNION SELECT * FROM secrets; --"

Resulting query after preparation:

SELECT * FROM example WHERE result=--42 OR name= 'foo
1 AND 1=0 UNION SELECT * FROM secrets; --';
Patches

The problem is resolved in v4.18.2.

Workarounds

Do not use the simple protocol or do not place a minus directly before a placeholder.

Go Vulnerability Database

SQL injection is possible when the database uses the non-default simple protocol, a minus sign directly precedes a numeric placeholder followed by a string placeholder on the same line, and both parameter values are user-controlled.

NVD (es)

pgx es un controlador PostgreSQL y un conjunto de herramientas para Go. Antes de la versión 4.18.2, la inyección SQL puede ocurrir cuando se cumplen todas las condiciones siguientes: se utiliza el protocolo simple no predeterminado; un marcador de posición para un valor numérico debe ir precedido inmediatamente de un signo menos; debe haber un segundo marcador de posición para un valor de cadena después del primer marcador de posición; ambos deben estar en la misma línea; y ambos valores de parámetros deben ser controlados por el usuario. El problema se resuelve en v4.18.2. Como solución alternativa, no utilice el protocolo simple ni coloque un signo menos directamente antes de un marcador de posición.

References

Related

Sources

SourceRecordLicence
CVE ListCVE-2024-27289 changed 2025-06-12CVE Terms of Use
GitHub Advisory DatabaseGHSA-m7wr-2xf7-cm9p changed 2026-09-10CC-BY-4.0
Go Vulnerability DatabaseGO-2024-2605 changed 2026-02-04CC-BY-4.0
NVDCVE-2024-27289 changed 2026-06-17Public domain