Patchfirst
CVE-2022-31197 High · 7.1 EPSS 2.4%

SQL Injection in ResultSet.refreshRow() with malicious column names in pgjdbc

Fix:upgrade postgresql to 42.4.4 or later also fixes CVE-2024-1597 Details ↓

pgjdbc · pgjdbc

Official description · CVE.org

PostgreSQL JDBC Driver (PgJDBC for short) allows Java programs to connect to a PostgreSQL database using standard, database independent Java code. The PGJDBC implementation of the `java.sql.ResultRow.refreshRow()` method is not performing escaping of column names so a malicious column name that contains a statement terminator, e.g. `;`, could lead to SQL injection. This could lead to executing additional SQL commands as the application's JDBC user. User applications that do not invoke the `ResultSet.refreshRow()` method are not impacted. User application that do invoke that method are impacted if the underlying database that they are querying via their JDBC application may be under the control of an attacker. The attack requires the attacker to trick the user into executing SQL against a table name who's column names would contain the malicious SQL and subsequently invoke the `refreshRow()` method on the ResultSet. Note that the application's JDBC user and the schema owner need not be the same. A JDBC application that executes as a privileged user querying database schemas owned by potentially malicious less-privileged users would be vulnerable. In that situation it may be possible for the malicious user to craft a schema that causes the application to execute commands as the privileged user. Patched versions will be released as `42.2.26` and `42.4.1`. Users are advised to upgrade. There are no known workarounds for this issue.

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

First seen exploited 3 years after disclosure.

  1. Disclosedday 0
  2. First seen exploitedVulnCheck KEV evidence+3 yrs

7 fixes in postgresql over 5 years. The latest fix listed for postgresql is 42.7.7.

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

  1. 42.2.13CVE-2020-136924 Jun 2020
  2. 42.3.2CVE-2022-217242 Feb 2022
  3. 42.3.3CVE-2022-265207 Mar 2022
  4. 42.4.1CVE-2022-311973 Aug 2022
  5. 42.5.1CVE-2022-4194623 Nov 2022
  6. 42.7.2CVE-2024-159719 Feb 2024
  7. 42.7.7CVE-2025-4914611 Jun 2025Latest listed

Affected versions and fixes

as published in the CVE record

pgjdbc pgjdbc

Affected: >= 42.2.0, < 42.2.26 · >= 42.3.0, < 42.4.1

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-r38f-c4h4-hqq2

Upgrade to 42.4.4 or later

Fixes this CVE and 1 other known vulnerability in this package (CVE-2024-1597).

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

First fixed in 42.4.1 for CVE-2022-31197.

Affected versions, by release line

If you runUpgrade to
42.4.0 up to 42.4.142.4.4first fix for this CVE: 42.4.1
42.3.0 up to 42.3.742.3.9first fix for this CVE: 42.3.7
All versions before 42.2.2642.2.28first fix for this CVE: 42.2.26

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

Check your lockfile against all CVEs

What security researchers reported

Not named in any threat report yet

Also mentioned in 2 community threat pulses (AlienVault OTX)

Weaker evidence

Pulses are indicator collections that anyone can publish. A mention is not confirmation of exploitation.

References

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