SQL injection can occur when all of the following conditions are met:
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; --';
The problem is resolved in v4.18.2.
Do not use the simple protocol or do not place a minus directly before a placeholder.
| Score | Percentile |
|---|---|
| 0.59% | 68.51% |
| Base score | Version | Severity | Vector |
|---|---|---|---|
| 8.1 | 3.1 | — |
|
| 8.7 | 4.0 | — |
|
| Type | Value |
|---|---|
| GHSA | GHSA-m7wr-2xf7-cm9p ↗ |
| CVE | CVE-2024-27289 ↗ |
| CWE id | Name |
|---|---|
| CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') |
Vulnerable version ranges and first patched releases as published by GitHub.
| Ecosystem | Package | Vulnerable range | First patched | Vulnerable functions |
|---|---|---|---|---|
| go | github.com/jackc/pgx | < 4.18.2 | 4.18.2 | — |
| go | github.com/jackc/pgx/v4 | < 4.18.2 | 4.18.2 | — |