Patchfirst
CVE-2024-1597 Critical · 10.0 EPSS 4.8%

pgjdbc SQL Injection via line comment generation

Fix:upgrade postgresql to 42.7.2 or later Details ↓

pgjdbc · pgjdbc

Summary

The pgjdbc PostgreSQL JDBC Driver is vulnerable to SQL injection in its SIMPLE query mode (PreferQueryMode=SIMPLE, which is not the default), where a numeric placeholder directly preceded by a minus sign and a string placeholder following it on the same line can be abused to inject SQL. An unauthenticated remote attacker can exploit this without user interaction by supplying a crafted string payload to an application that uses the affected configuration, bypassing the protection normally provided by parameterized queries.

Official description · CVE.org

pgjdbc, the PostgreSQL JDBC Driver, allows attacker to inject SQL if using PreferQueryMode=SIMPLE. Note this is not the default. In the default mode there is no vulnerability. A placeholder for a numeric value must be immediately preceded by a minus. There must be a second placeholder for a string value after the first placeholder; both must be on the same line. By constructing a matching string payload, the attacker can inject SQL to alter the query,bypassing the protections that parameterized queries bring against SQL Injection attacks. Versions before 42.7.2, 42.6.1, 42.5.5, 42.4.4, 42.3.9, and 42.2.28 are affected.

Breakdown
60.4 / 100
Exploited
Yes, in VulnCheck KEV
Reports
0
Tactics
0/15

First seen exploited 8 months after disclosure.

  1. Disclosedday 0
  2. First seen exploitedVulnCheck KEV evidence+8 mo

2 related vulnerabilities in the same code over 3 months. The latest fix listed for postgresql is 42.7.12.

Linked vulnerabilitiesLinked by evidence that a fix failed or the same code was patched again. Oldest first.

  1. This CVECVE-2024-1597pgjdbc SQL Injection via line comment generation19 Feb 2024
  2. relatedHigh

    Why these are linked:

    CVE-2024-32888Amazon JDBC Driver for Redshift SQL Injection via line comment…15 May 2024

Fixes in postgresqlMaven package, by fixed version. Earlier and later fixes in the same package, not necessarily the same bug.

  1. 42.3.3CVE-2022-265207 Mar 2022
  2. 42.4.1CVE-2022-311973 Aug 2022
  3. 42.5.1CVE-2022-4194623 Nov 2022
  4. 42.7.2CVE-2024-159719 Feb 2024
  5. 42.7.7CVE-2025-4914611 Jun 2025
  6. 42.7.11CVE-2026-4219829 Apr 2026
  7. 42.7.12CVE-2026-542916 Jul 2026Latest listed

Affected versions and fixes

as published in the CVE record

pgjdbc pgjdbc

Affected: < 42.7.2 · < 42.6.1 · < 42.5.5 · < 42.4.4 · < 42.3.9 · < 42.2.28

Workaround

Don't use SimpleQuery mode

Am I affected? What do I upgrade to?

From GitHub Security Advisories and OSV

1 package in 1 ecosystem. Main package: org.postgresql:postgresql.

Mavenorg.postgresql:postgresqlGHSA-24rp-q3w6-vc56

Upgrade to 42.7.2 or later

Set the version to 42.7.2 or later in your pom.xml or build.gradle.

The first fix for CVE-2024-1597.

Affected versions, by release line

If you runUpgrade to
42.7.0 up to 42.7.242.7.2
42.6.0 up to 42.6.142.6.1
42.5.0 up to 42.5.542.5.5
42.4.0 up to 42.4.442.4.4
42.3.0 up to 42.3.942.3.9
All versions before 42.2.2842.2.28

“Up to” means the second version is the fix and is not affected.

Check your lockfile against all CVEs

References

9 links, grouped by NVD tag
↑ ↓ chooseEnter openEsc close