GHSA-m7wr-2xf7-cm9p

Suggest an improvement
Source
https://github.com/advisories/GHSA-m7wr-2xf7-cm9p
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2024/03/GHSA-m7wr-2xf7-cm9p/GHSA-m7wr-2xf7-cm9p.json
JSON Data
https://api.test.osv.dev/v1/vulns/GHSA-m7wr-2xf7-cm9p
Aliases
Related
Published
2024-03-04T20:13:11Z
Modified
2024-10-15T05:42:09.664241Z
Severity
  • 8.1 (High) CVSS_V3 - CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H CVSS Calculator
  • 8.7 (High) CVSS_V4 - CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N CVSS Calculator
Summary
pgx SQL Injection via Line Comment Creation
Details

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.

Database specific
{
    "nvd_published_at": "2024-03-06T19:15:08Z",
    "cwe_ids": [
        "CWE-89"
    ],
    "severity": "HIGH",
    "github_reviewed": true,
    "github_reviewed_at": "2024-03-04T20:13:11Z"
}
References

Affected packages

Go / github.com/jackc/pgx

Package

Name
github.com/jackc/pgx
View open source insights on deps.dev
Purl
pkg:golang/github.com/jackc/pgx

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
4.18.2

Go / github.com/jackc/pgx/v4

Package

Name
github.com/jackc/pgx/v4
View open source insights on deps.dev
Purl
pkg:golang/github.com/jackc/pgx/v4

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
4.18.2