# CVE-2024-27304: pgx SQL Injection via Protocol Message Size Overflow

> An integer overflow in the pgx Go driver allows attackers to inject SQL by sending oversized messages, potentially leading to unauthorized database access or modification.

- **Severity:** Critical 9.8 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 6 Mar 2024
- **Updated:** 12 Dec 2024
- **Also known as:** AZL-35752, AZL-35762, CLEANSTART-2026-LT14460, CLEANSTART-2026-VJ98970, DEBIAN-CVE-2024-27304, GHSA-7jwh-3vrq-q3m8, GHSA-mrww-27vc-gghv, GO-2024-2606, UBUNTU-CVE-2024-27304

## What is CVE-2024-27304?

CVE-2024-27304 is a critical SQL injection vulnerability in jackc pgx, published on 6 Mar 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

pgx is a PostgreSQL driver and toolkit for Go. SQL injection can occur if an attacker can cause a single query or bind message to exceed 4 GB in size. An integer overflow in the calculated message size can cause the one large message to be sent as multiple messages under the attacker's control. The problem is resolved in v4.18.2 and v5.5.4. As a workaround, reject user input large enough to cause a single query or bind message to exceed 4 GB in size.

Weakness: CWE-89 (Improper Neutralization of Special Elements used in an SQL Command), CWE-190 (Integer Overflow or Wraparound)

## Which versions are affected by CVE-2024-27304?

16 open source packages ship an affected version, including github.com/jackc/pgx, github.com/jackc/pgproto3 and github.com/jackc/pgproto3/v2. It affects 2 products.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/jackc/pgx` | Go | All versions | None |
| `github.com/jackc/pgx` | Go | All versions | 4.18.2 |
| `github.com/jackc/pgx` | Go | All versions | 4.18.2 |
| `github.com/jackc/pgx` | Go | From 5.0.0 | 5.5.4 |
| `github.com/jackc/pgx` | Go | From 5.0.0 | 5.5.4 |
| `github.com/jackc/pgproto3` | Go | All versions | 2.3.3 |
| `github.com/jackc/pgproto3` | Go | All versions | 2.3.3 |
| `github.com/jackc/pgproto3/v2` | Go | All versions | 2.3.3 |
| `github.com/jackc/pgproto3/v2` | Go | All versions | 2.3.3 |
| `github.com/jackc/pgproto3/v2` | Go | All versions | 2.3.3 |
| `github.com/jackc/pgx/v4` | Go | All versions | 4.18.2 |
| `github.com/jackc/pgx/v4` | Go | All versions | 4.18.2 |
| `github.com/jackc/pgx/v4` | Go | All versions | 4.18.2 |
| `github.com/jackc/pgx/v5` | Go | From 5.0.0 | 5.5.4 |
| `github.com/jackc/pgx/v5` | Go | From 5.0.0 | 5.5.4 |
| `github.com/jackc/pgx/v5` | Go | From 5.0.0 | 5.5.4 |

Products: Jackc Pgproto3, Jackc Pgx.

## How do I fix CVE-2024-27304?

Upgrade github.com/jackc/pgx to a fixed version for your release line: 4.18.2 or 5.5.4.

## Is CVE-2024-27304 being exploited?

There is no known exploitation of CVE-2024-27304 in the wild and no public exploit code.

Public exploit code:

- PoC of "DEF CON 32 - SQL Injection Isn't Dead Smuggling Queries at the Protocol Level - Paul Gerste" (github_poc): https://github.com/roaris/CVE-2024-27304-PoC

## Other vulnerabilities in jackc pgx

- [CVE-2026-32286](https://insights.sbomify.com/CVE-2026-32286/): Denial of service in github.com/jackc/pgproto3/v2 (high 7.5)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-27304 and fix it if it is affected.

What it is: CVE-2024-27304 is a critical SQL injection vulnerability in jackc pgx, published on 6 Mar 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2024-27304 in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/jackc/pgx (Go): affected all versions; no fix listed
- github.com/jackc/pgx (Go): affected all versions; fixed in 4.18.2
- github.com/jackc/pgx (Go): affected all versions; fixed in 4.18.2
- github.com/jackc/pgx (Go): affected from 5.0.0; fixed in 5.5.4
- github.com/jackc/pgx (Go): affected from 5.0.0; fixed in 5.5.4
- github.com/jackc/pgproto3 (Go): affected all versions; fixed in 2.3.3
- github.com/jackc/pgproto3 (Go): affected all versions; fixed in 2.3.3
- github.com/jackc/pgproto3/v2 (Go): affected all versions; fixed in 2.3.3
- github.com/jackc/pgproto3/v2 (Go): affected all versions; fixed in 2.3.3
- github.com/jackc/pgproto3/v2 (Go): affected all versions; fixed in 2.3.3
- github.com/jackc/pgx/v4 (Go): affected all versions; fixed in 4.18.2
- github.com/jackc/pgx/v4 (Go): affected all versions; fixed in 4.18.2

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2024-27304/ (Markdown: https://insights.sbomify.com/CVE-2024-27304/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2024-27304
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-27304
- OSV: https://osv.dev/vulnerability/CVE-2024-27304

---
From sbomify Insights: https://insights.sbomify.com/CVE-2024-27304/
Summaries are generated and may contain mistakes; the official description above is the record.
