CVE-2024-27289: Github.com/jackc/pgx SQL Injection Vulnerability

HIGH
Advisory Identifier: GHSA-m7wr-2xf7-cm9p
CVSS 8.1
CWE-89
Published
Advisory Summary

CVE-2024-27289 is a HIGH (CVSS 8.1) sql injection vulnerability (CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')) affecting Github.com/jackc/pgx libraries in the Go ecosystem. The issue involves pgx sql injection via line comment creation. Remediation is available by upgrading affected packages to version 4.18.2.

CVE-2024-27289 at a Glance

CVE Identifier CVE-2024-27289
GHSA Identifier GHSA-m7wr-2xf7-cm9p
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Affected Product Github.com/jackc/pgx
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 8.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2024-27289

To remediate this vulnerability, upgrade all affected Github.com/jackc/pgx dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/jackc/pgx fixed: 4.18.2
Upgrade github.com/jackc/pgx to 4.18.2
github.com/jackc/pgx/v4 fixed: 4.18.2
Upgrade github.com/jackc/pgx/v4 to 4.18.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for github.com/jackc/pgx

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-27289, inspect your project dependencies for Github.com/jackc/pgx:

inspect dependencies for github.com/jackc/pgx

Analyze the terminal output to locate any version of Github.com/jackc/pgx in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.18.2), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the product constructs all or part of an sql command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended sql command when it is sent to a downstream component. without sufficient removal or quoting of sql syntax in user-controllable inputs, the generated sql query can cause those inputs to be interpreted as sql instead of ordinary user data. In Github.com/jackc/pgx, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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: ```go // connection string includes "prefer_simple_protocol=true" // or // directly enabled in code config.ConnConfig.PreferSimpleProtocol = true ``` Parameterized query: ```sql 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: ```sql 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.

CVE-2024-27289 Affected Github.com/jackc/pgx Versions

2 component(s)
Fixed Versions:
4.18.2
Product / Package Ecosystem Affected Versions Fixed Version
github.com/jackc/pgx
Go
< 4.18.2
4.18.2
github.com/jackc/pgx/v4
Go
< 4.18.2
4.18.2

References

Frequently Asked Questions

What is CVE-2024-27289?
CVE-2024-27289 is a security vulnerability in Github.com/jackc/pgx involving pgx SQL Injection via Line Comment Creation under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Which Github.com/jackc/pgx versions are affected?
Affected versions include releases prior to 4.18.2 across affected packages: github.com/jackc/pgx, github.com/jackc/pgx/v4.
What version fixes CVE-2024-27289?
Upgrading to 4.18.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/jackc/pgx affected?
Yes, github.com/jackc/pgx is affected in releases prior to 4.18.2. Upgrade your dependency to 4.18.2 or later.
Is github.com/jackc/pgx/v4 affected?
Yes, github.com/jackc/pgx/v4 is affected in releases prior to 4.18.2. Upgrade your dependency to 4.18.2 or later.
What is the CVSS score of CVE-2024-27289?
CVE-2024-27289 has a CVSS v3.1 base score of 8.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2024-27289?
CVE-2024-27289 is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.).
How can I check Go dependencies for CVE-2024-27289?
Run the dependency tree command: 'inspect dependencies for github.com/jackc/pgx'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-m7wr-2xf7-cm9p",
  "modified" : "2025-06-13T20:45:26Z",
  "published" : "2024-03-04T20:13:11Z",
  "aliases" : [ "CVE-2024-27289" ],
  "summary" : "pgx SQL Injection via Line Comment Creation",
  "details" : "### Impact\n\nSQL injection can occur when all of the following conditions are met:\n\n1. The non-default simple protocol is used.\n2. A placeholder for a numeric value must be immediately preceded by a minus.\n3. There must be a second placeholder for a string value after the first placeholder; both\nmust be on the same line.\n4. Both parameter values must be user-controlled.\n\ne.g. \n\nSimple mode must be enabled:\n\n```go\n// connection string includes \"prefer_simple_protocol=true\"\n// or\n// directly enabled in code\nconfig.ConnConfig.PreferSimpleProtocol = true\n```\n\nParameterized query:\n\n```sql\nSELECT * FROM example WHERE result=-$1 OR name=$2;\n```\n\nParameter values:\n\n`$1` => `-42`\n`$2` => `\"foo\\n 1 AND 1=0 UNION SELECT * FROM secrets; --\"`\n\nResulting query after preparation:\n\n```sql\nSELECT * FROM example WHERE result=--42 OR name= 'foo\n1 AND 1=0 UNION SELECT * FROM secrets; --';\n```\n\n### Patches\n\nThe problem is resolved in v4.18.2.\n\n### Workarounds\n\nDo not use the simple protocol or do not place a minus directly before a placeholder.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "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"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/jackc/pgx"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.18.2"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/jackc/pgx/v4"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.18.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/jackc/pgx/security/advisories/GHSA-m7wr-2xf7-cm9p"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-27289"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jackc/pgx/commit/f94eb0e2f96782042c96801b5ac448f44f0a81df"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/jackc/pgx"
  }, {
    "type" : "WEB",
    "url" : "https://www.sonarsource.com/blog/double-dash-double-trouble-a-subtle-sql-injection-flaw"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-89" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-03-04T20:13:11Z",
    "nvd_published_at" : "2024-03-06T19:15:08Z"
  }
}