Critical

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

  • Disclosed: 21.02.2024
  • Updated: 11.10.2026 13:20

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. -)
  2. There must be a second placeholder for a string value after the first placeholder on the same line.
  3. 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

java
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:

sql
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:

sql
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.)

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
Java / Kotlin (Maven) org.postgresql:postgresql < 42.2.28, >= 42.3.0, < 42.3.9, >= 42.4.0, < 42.4.4, >= 42.5.0, < 42.5.5, >= 42.6.0, < 42.6.1, >= 42.7.0, < 42.7.2 42.2.28, 42.3.9, 42.4.4, 42.5.5, 42.6.1, 42.7.2

References

CVSS score 10/10
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H
Weakness (CWE)
CWE-89
Platform
Java / Kotlin (Maven)
Package
org.postgresql:postgresql
Disclosed
21.02.2024
Updated
11.10.2026 13:20

Sources and licenses

OSV / GitHub Advisory Database - GHSA-24rp-q3w6-vc56 - CC BY 4.0

Vulnerability history: org.postgresql:postgresql

All published vulnerabilities of this package (Java / Kotlin (Maven)), newest first. Shows whether this is a one-off slip or a package that needs watching.

All (10) in the archive
Total entries
10
First → latest
02.2022 07.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • Critical 1
  • High 7
  • Medium 2

Disclosures per year

  1. 2022: 6
  2. 2023: 0
  3. 2024: 1
  4. 2025: 1
  5. 2026: 2
Severity:
  1. High · 7.5 CVE-2026-42198 >= 42.2.0, < 42.7.11 42.7.11
  2. org.postgresql:postgresql vulnerable to SQL Injection via line comment generation this entry
    Critical · 10.0 CVE-2024-1597 < 42.2.28, >= 42.3.0, < 42.3.9, >= 42.4.0, < 42.4.4, >= 42.5.0, < 42.5.5, >= 42.6.0, < 42.6.1, >= 42.7.0, < 42.7.2 42.2.28, 42.3.9, 42.4.4, 42.5.5, 42.6.1, 42.7.2
  3. High · 7.1 CVE-2022-31197 < 42.2.26, >= 42.4.0, < 42.4.1, >= 42.3.0, < 42.3.7 42.2.26, 42.4.1, 42.3.7
  4. High · 7.7 CVE-2020-13692 >= 9.4.1212.jre6, < 42.2.13 42.2.13
  5. High · 7.0 CVE-2022-21724 >= 9.4.1208, < 42.2.25, >= 42.3.0, < 42.3.2 42.2.25, 42.3.2

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.