CriticalGHSA-24rp-q3w6-vc56BIT-postgresql-jdbc-driver-2024-1597CVE-2024-1597

org.postgresql:postgresql vulnerable to SQL Injection via line comment generation

Published 21 Feb 2024 · Updated 10 Sept 2026

Is your project on an affected org.postgresql:postgresql?

Private repo? Upload its lockfile instead, or connect GitHub to check every repo.

Look after several Java apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie

Affected packages

Affected
<42.2.28
Fixed in
42.2.28
Update to the fixed version for your release line, for example:mvn versions:use-dep-version -Dincludes=org.postgresql:postgresql -DdepVersion=42.2.28 -DforceVersion=true
Affected
>=42.3.0 <42.3.9
Fixed in
42.3.9
Update to the fixed version for your release line, for example:mvn versions:use-dep-version -Dincludes=org.postgresql:postgresql -DdepVersion=42.3.9 -DforceVersion=true
Affected
>=42.4.0 <42.4.4
Fixed in
42.4.4
Update to the fixed version for your release line, for example:mvn versions:use-dep-version -Dincludes=org.postgresql:postgresql -DdepVersion=42.4.4 -DforceVersion=true
Affected
>=42.5.0 <42.5.5
Fixed in
42.5.5
Update to the fixed version for your release line, for example:mvn versions:use-dep-version -Dincludes=org.postgresql:postgresql -DdepVersion=42.5.5 -DforceVersion=true
Affected
>=42.6.0 <42.6.1
Fixed in
42.6.1
Update to the fixed version for your release line, for example:mvn versions:use-dep-version -Dincludes=org.postgresql:postgresql -DdepVersion=42.6.1 -DforceVersion=true
Affected
>=42.7.0 <42.7.2
Fixed in
42.7.2
Update to the fixed version for your release line, for example:mvn versions:use-dep-version -Dincludes=org.postgresql:postgresql -DdepVersion=42.7.2 -DforceVersion=true

Details

Impact

SQL injection is possible when using the non-default connection property preferQueryMode=simple in combination with application code that has a vulnerable SQL that negates a parameter value.

There is no vulnerability in the driver when using the default query mode. Users that do not override the query mode are not impacted.

Exploitation

To exploit this behavior the following conditions must be met:

1. A placeholder for a numeric value must be immediately preceded by a minus (i.e. -) 1. There must be a second placeholder for a string value after the first placeholder on the same line. 1. Both parameters must be user controlled.

The prior behavior of the driver when operating in simple query mode would inline the negative value of the first parameter and cause the resulting line to be treated as a -- SQL comment. That would extend to the beginning of the next parameter and cause the quoting of that parameter to be consumed by the comment line. If that string parameter includes a newline, the resulting text would appear unescaped in the resulting SQL.

When operating in the default extended query mode this would not be an issue as the parameter values are sent separately to the server. Only in simple query mode the parameter values are inlined into the executed SQL causing this issue.

Example

PreparedStatement stmt = conn.prepareStatement("SELECT -?, ?");
stmt.setInt(1, -1);
stmt.setString(2, "\nWHERE false --");
ResultSet rs = stmt.executeQuery();

The resulting SQL when operating in simple query mode would be:

SELECT --1,'
WHERE false --'

The contents of the second parameter get injected into the command. Note how both the number of result columns and the WHERE clause of the command have changed. A more elaborate example could execute arbitrary other SQL commands.

Patch

Problem will be patched upgrade to 42.7.2, 42.6.1, 42.5.5, 42.4.4, 42.3.9, 42.2.28, 42.2.28.jre7

The patch fixes the inlining of parameters by forcing them all to be serialized as wrapped literals. The SQL in the prior example would be transformed into:

SELECT -('-1'::int4), ('
WHERE false --')

Workarounds

Do not use the connection propertypreferQueryMode=simple. (*NOTE: If you do not explicitly specify a query mode then you are using the default of extended and are not impacted by this issue.*)

Is GHSA-24rp-q3w6-vc56 in any of your client repos?

Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected org.postgresql:postgresql, and gives you the command that fixes it.

More advisories for org.postgresql:postgresql

  • HighCVE-2026-54291PostgreSQL JDBC Driver: Silent channel-binding authentication downgrade via unsupported certificate algorithms · 21 Jul 2026
  • HighCVE-2026-42198pgjdbc: Unbounded PBKDF2 iterations in SCRAM authentication allows CPU exhaustion DoS · 5 May 2026
  • HighCVE-2025-49146pgjdbc Client Allows Fallback to Insecure Authentication Despite channelBinding=require Configuration · 11 Jun 2025
  • MediumCVE-2022-41946TemporaryFolder on unix-like systems does not limit access to created files · 23 Nov 2022
  • HighCVE-2022-31197PostgreSQL JDBC Driver SQL Injection in ResultSet.refreshRow() with malicious column names · 6 Aug 2022
  • HighCVE-2012-1618Unescaped parameters in the PostgreSQL JDBC driver · 17 May 2022
All 11 advisories for org.postgresql:postgresql

References

Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.