CVE-2024-32655 Npgsql Vulnerable to SQL Injection via Protocol Message Size Overflow

High 8.1 Published Updated

Attackers can inject arbitrary SQL statements by exploiting an integer overflow in Npgsql's protocol message construction, affecting .NET applications using PostgreSQL.

Exploited in the wild
Not known
Login needed
Not needed
Attackable
Over the internet
Victim action needed
Not needed
Fix
Available

What is CVE-2024-32655?

CVE-2024-32655 is a high-severity SQL injection vulnerability in npgsql, published on 9 May 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

Official description

Npgsql is the .NET data provider for PostgreSQL. The `WriteBind()` method in `src/Npgsql/Internal/NpgsqlConnector.FrontendMessages.cs` uses `int` variables to store the message length and the sum of parameter lengths. Both variables overflow when the sum of parameter lengths becomes too large. This causes Npgsql to write a message size that is too small when constructing a Postgres protocol message to send it over the network to the database. When parsing the message, the database will only read a small number of bytes and treat any following bytes as new messages while they belong to the old message. Attackers can abuse this to inject arbitrary Postgres protocol messages into the connection, leading to the execution of arbitrary SQL statements on the application's behalf. This vulnerability is fixed in 4.0.14, 4.1.13, 5.0.18, 6.0.11, 7.0.7, and 8.0.3.

Weakness: CWE-89, CWE-190

Which versions are affected by CVE-2024-32655?

12 open source packages ship an affected version, including Npgsql.

PackageAffectedFixed in
Npgsql NuGetAll versions4.0.14
Npgsql NuGetAll versions4.0.14
Npgsql NuGetFrom 4.1.04.1.13
Npgsql NuGetFrom 4.1.04.1.13
Npgsql NuGetFrom 5.0.05.0.18
Npgsql NuGetFrom 5.0.05.0.18
6 more packages
Npgsql NuGetFrom 6.0.06.0.11
Npgsql NuGetFrom 6.0.06.0.11
Npgsql NuGetFrom 7.0.07.0.7
Npgsql NuGetFrom 7.0.07.0.7
Npgsql NuGetFrom 8.0.08.0.3
Npgsql NuGetFrom 8.0.08.0.3

How do I fix CVE-2024-32655?

Upgrade Npgsql to a fixed version for your release line: 4.0.14, 4.1.13, 5.0.18 or 6.0.11.

Use parameterised queries everywhere and never build SQL by joining strings. Upgrade affected software first; a web application firewall only buys time. More about SQL injection.

Is CVE-2024-32655 being exploited?

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

Sources

Also known as GHSA-x9vc-6hfv-hg8c, UBUNTU-CVE-2024-32655.

Is CVE-2024-32655 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free