CVE-2024-32655: Npgsql SQL Injection Vulnerability

HIGH
Advisory Identifier: GHSA-x9vc-6hfv-hg8c
CVSS 8.1
CWE-190 CWE-89
Published
Advisory Summary

CVE-2024-32655 is a HIGH (CVSS 8.1) sql injection vulnerability (CWE-190: Integer Overflow or Wraparound) affecting Npgsql libraries in the NuGet ecosystem. The issue involves npgsql vulnerable to sql injection via protocol message size overflow. Remediation is available by upgrading affected packages to version 8.0.3, 4.0.14, 4.1.13, 5.0.18, 6.0.11, 7.0.7.

CVE-2024-32655 at a Glance

CVE Identifier CVE-2024-32655
GHSA Identifier GHSA-x9vc-6hfv-hg8c
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-190: Integer Overflow or Wraparound
Affected Product Npgsql
Package Ecosystem NuGet
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-32655

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

Npgsql fixed: 8.0.3
Upgrade Npgsql to 8.0.3
Npgsql fixed: 4.0.14
Upgrade Npgsql to 4.0.14
Npgsql fixed: 4.1.13
Upgrade Npgsql to 4.1.13
Npgsql fixed: 5.0.18
Upgrade Npgsql to 5.0.18
Npgsql fixed: 6.0.11
Upgrade Npgsql to 6.0.11
Npgsql fixed: 7.0.7
Upgrade Npgsql to 7.0.7
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 Npgsql

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-32655, inspect your project dependencies for Npgsql:

inspect dependencies for Npgsql

Analyze the terminal output to locate any version of Npgsql in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 8.0.3), 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-190: Integer Overflow or Wraparound, where the product performs a calculation that can produce an integer overflow or wraparound when the logic assumes that the resulting value will always be larger than the original value. this occurs when an integer value is incremented to a value that is too large to store in the associated representation. when this occurs, the value may become a very small or negative number. In Npgsql, 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

### Summary 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. ### Impact Attackers can issue arbitrary SQL statements to the database on behalf of the application. The final impact depends on the application that uses Npgsql, the data it stores in Postgres, etc.

CVE-2024-32655 Affected Npgsql Versions

6 component(s)
Fixed Versions:
8.0.34.0.144.1.135.0.186.0.117.0.7
Product / Package Ecosystem Affected Versions Fixed Version
Npgsql
NuGet
≥ 8.0.0
< 8.0.3
8.0.3
Npgsql
NuGet
< 4.0.14
4.0.14
Npgsql
NuGet
≥ 4.1.0
< 4.1.13
4.1.13
Npgsql
NuGet
≥ 5.0.0
< 5.0.18
5.0.18
Npgsql
NuGet
≥ 6.0.0
< 6.0.11
6.0.11
Npgsql
NuGet
≥ 7.0.0
< 7.0.7
7.0.7

References

GitHub Advisory / Wiki ADVISORY
https://github.com/npgsql/npgsql/security/advisories/GHSA-x9vc-6hfv-hg8c
NVD — CVE-2024-32655 NVD
https://nvd.nist.gov/vuln/detail/CVE-2024-32655
Security Fix Commit FIX COMMIT
https://github.com/npgsql/npgsql/commit/091655eed0c84e502ab424950c930339d17c1928
Security Fix Commit FIX COMMIT
https://github.com/npgsql/npgsql/commit/3183efb2bdcca159c8c2e22af57e18ea8f853cf0
Security Fix Commit FIX COMMIT
https://github.com/npgsql/npgsql/commit/67acbe027e28477ac2199e15cfb554bb2ffaf169
Security Fix Commit FIX COMMIT
https://github.com/npgsql/npgsql/commit/703d9af8fa48dfe8c0180e36edb8278f34342d7b
Security Fix Commit FIX COMMIT
https://github.com/npgsql/npgsql/commit/a22a42d8141d7a3528f43c02c095a409507cf1af
Security Fix Commit FIX COMMIT
https://github.com/npgsql/npgsql/commit/e34e2ba8042e666d9af54a1b255fba4d5b11df56
Security Fix Commit FIX COMMIT
https://github.com/npgsql/npgsql/commit/f7e7ead0702d776a8f551f5786c4cac2d65c4bc6
www.youtube.com/watch WEB
https://www.youtube.com/watch?v=Tfg1B8u1yvE
Npgsql Release RELEASE
https://github.com/npgsql/npgsql/releases/tag/v8.0.3
Npgsql Release RELEASE
https://github.com/npgsql/npgsql/releases/tag/v7.0.7
Npgsql Release RELEASE
https://github.com/npgsql/npgsql/releases/tag/v6.0.11
Npgsql Release RELEASE
https://github.com/npgsql/npgsql/releases/tag/v5.0.18
Npgsql Release RELEASE
https://github.com/npgsql/npgsql/releases/tag/v4.1.13
Npgsql Release RELEASE
https://github.com/npgsql/npgsql/releases/tag/v4.0.14
Npgsql Source Repository REPOSITORY
https://github.com/npgsql/npgsql/files/14309397/npgsql-protocol-overflow-poc.zip
Npgsql Source Repository REPOSITORY
https://github.com/npgsql/npgsql/files/14309386/Npgsql.Security.Advisory.pdf
Npgsql Source Repository REPOSITORY
https://github.com/npgsql/npgsql

Frequently Asked Questions

What is CVE-2024-32655?
CVE-2024-32655 is a security vulnerability in Npgsql involving Npgsql vulnerable to SQL Injection via Protocol Message Size Overflow under CWE-190: Integer Overflow or Wraparound.
Which Npgsql versions are affected?
Affected versions include releases prior to 8.0.3, 4.0.14, 4.1.13, 5.0.18, 6.0.11, 7.0.7 across affected packages: Npgsql.
What version fixes CVE-2024-32655?
Upgrading to 8.0.3, 4.0.14, 4.1.13, 5.0.18, 6.0.11, 7.0.7 (or the latest patched release for your respective branch) resolves the vulnerability.
Is Npgsql affected?
Yes, Npgsql is affected in releases prior to 8.0.3, 4.0.14, 4.1.13, 5.0.18, 6.0.11, 7.0.7. Upgrade your dependency to 8.0.3, 4.0.14, 4.1.13, 5.0.18, 6.0.11, 7.0.7 or later.
What is the CVSS score of CVE-2024-32655?
CVE-2024-32655 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-32655?
CVE-2024-32655 is classified under CWE-190: Integer Overflow or Wraparound (The product performs a calculation that can produce an integer overflow or wraparound when the logic assumes that the resulting value will always be larger than the original value. This occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may become a very small or negative number.).
How can I check NuGet dependencies for CVE-2024-32655?
Run the dependency tree command: 'inspect dependencies for Npgsql'. 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-x9vc-6hfv-hg8c",
  "modified" : "2024-12-12T22:27:07Z",
  "published" : "2024-05-09T15:12:49Z",
  "aliases" : [ "CVE-2024-32655" ],
  "summary" : "Npgsql vulnerable to SQL Injection via Protocol Message Size Overflow",
  "details" : "### Summary\nThe `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.\n\nThis 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.\n\nAttackers 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.\n\n### Impact\nAttackers can issue arbitrary SQL statements to the database on behalf of the application. The final impact depends on the application that uses Npgsql, the data it stores in Postgres, etc.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "NuGet",
      "name" : "Npgsql"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "8.0.0"
      }, {
        "fixed" : "8.0.3"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "NuGet",
      "name" : "Npgsql"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.0.14"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 4.0.13"
    }
  }, {
    "package" : {
      "ecosystem" : "NuGet",
      "name" : "Npgsql"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.1.0"
      }, {
        "fixed" : "4.1.13"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "NuGet",
      "name" : "Npgsql"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "5.0.0"
      }, {
        "fixed" : "5.0.18"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "NuGet",
      "name" : "Npgsql"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "6.0.0"
      }, {
        "fixed" : "6.0.11"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "NuGet",
      "name" : "Npgsql"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "7.0.0"
      }, {
        "fixed" : "7.0.7"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/security/advisories/GHSA-x9vc-6hfv-hg8c"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-32655"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/commit/091655eed0c84e502ab424950c930339d17c1928"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/commit/3183efb2bdcca159c8c2e22af57e18ea8f853cf0"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/commit/67acbe027e28477ac2199e15cfb554bb2ffaf169"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/commit/703d9af8fa48dfe8c0180e36edb8278f34342d7b"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/commit/a22a42d8141d7a3528f43c02c095a409507cf1af"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/commit/e34e2ba8042e666d9af54a1b255fba4d5b11df56"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/commit/f7e7ead0702d776a8f551f5786c4cac2d65c4bc6"
  }, {
    "type" : "WEB",
    "url" : "https://www.youtube.com/watch?v=Tfg1B8u1yvE"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/releases/tag/v8.0.3"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/releases/tag/v7.0.7"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/releases/tag/v6.0.11"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/releases/tag/v5.0.18"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/releases/tag/v4.1.13"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/releases/tag/v4.0.14"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/files/14309397/npgsql-protocol-overflow-poc.zip"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/npgsql/npgsql/files/14309386/Npgsql.Security.Advisory.pdf"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/npgsql/npgsql"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-190", "CWE-89" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-05-09T15:12:49Z",
    "nvd_published_at" : "2024-05-14T15:36:51Z"
  }
}