NewApp Monitoring is liveSign up free
AgentbeamBeta
Open-source package vulnerability · Go

CVE-2024-27289: pgx SQL Injection via Line Comment Creation

highCVSS 4.0 8.7 · 3.1 8.1GHSA-m7wr-2xf7-cm9p

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.

Published Mar 4, 2024 · Updated Mar 15, 2026

Affected packages

github.com/jackc/pgx

Ecosystem
Go
Affected
< 4.18.2
Fixed in
4.18.2
Check
go list -m github.com/jackc/pgx

github.com/jackc/pgx/v4

Ecosystem
Go
Affected
< 4.18.2
Fixed in
4.18.2
Check
go list -m github.com/jackc/pgx/v4

Advisory details

From the GitHub Advisory Database (CC BY 4.0).

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.

  1. 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.

Credited to paul-gerste-sonarsource.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology

More Go vulnerabilities

All Go entries