NIST deprecates RSA-2048 from 2030. Find every one of them before attackers do.
☕
☕ Maven
Not in CISA KEV
HIGH severity

CVE-2022-31197 — postgresql

HIGHFix: pgjdbc/pgjdbc@739e599

CVE-2022-31197 is a high-severity (CVSS 7.1) SQL Injection vulnerability in org.postgresql:postgresql. 1 public exploit or proof-of-concept reference is indexed, so weaponization risk is real. A fix is available for org.postgresql:postgresql — see the affected versions and patch details below.

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

Also known asBIT-postgresql-jdbc-driver-2022-31197GHSA-r38f-c4h4-hqq2
Published
Updated
Affected
3 pkgs
Patched
3 / 3
Exploits
1 known
Exploitation data as of Nov 5, 2026 · OSV.dev, NVD, FIRST.org (EPSS)

Exploitation Status

Proof-of-concept exploit code exists

  • CISA’s SSVC triage found public proof-of-concept exploit code for this CVE, though no confirmed active exploitation.
  • A successful exploit gives an attacker total control of the affected component, not partial access.

Exploitation and automatability from CISA’s SSVC triage for CVE-2022-31197.

EPSS Exploitation Probability

via FIRST.org ↗
2.4%probability of exploitation in next 30 days
Lower Risk0.00%
Lower risk than most CVEs84th percentile — riskier than 84% of all scored CVEsHighest risk
1.16%1.86%2.57%3.27%2.8%2.4%May 26Sep 26Nov 26

Probability of exploitation in the next 30 days, from FIRST.org EPSS.

How urgent is this, really

Where this sits among everything scored

Real-World Exposure

3 pkgs affected
☕org.postgresql:postgresql☕org.postgresql:postgresql☕org.postgresql:postgresql

Real-time download stats are indexed for npm and PyPI packages. This vulnerability affects Maven packages — download data is not available via public APIs for these ecosystems.

Description

Impact

What kind of vulnerability is it? Who is impacted?

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.

For example:

CREATE TABLE refresh_row_example (
  id     int PRIMARY KEY,
  "1 FROM refresh_row_example; SELECT pg_sleep(10); SELECT * " int
);

This example has a table with two columns. The name of the second column is crafted to contain a statement terminator followed by additional SQL. Invoking the ResultSet.refreshRow() on a ResultSet that queried this table, e.g. SELECT * FROM refresh_row, would cause the additional SQL commands such as the SELECT pg_sleep(10) invocation to be executed.

As the multi statement command would contain multiple results, it would not be possible for the attacker to get data directly out of this approach as the ResultSet.refreshRow() method would throw an exception. However, the attacker could execute any arbitrary SQL including inserting the data into another table that could then be read or any other DML / DDL statement.

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.

Patches

Has the problem been patched? What versions should users upgrade to?

Yes, versions 42.2.26, 42.3.7, and 42.4.1 have been released with a fix.

Workarounds

Is there a way for users to fix or remediate the vulnerability without upgrading?

Check that you are not using the ResultSet.refreshRow() method.

If you are, ensure that the code that executes that method does not connect to a database that is controlled by an unauthenticated or malicious user. If your application only connects to its own database with a fixed schema with no DDL permissions, then you will not be affected by this vulnerability as it requires a maliciously crafted schema.

Affected Packages

3 total 3 fixed
EcosystemPackageVulnerable rangeFix
☕Mavenorg.postgresql:postgresqlall versions42.2.26org.postgresql:postgresql:42.2.26
☕Mavenorg.postgresql:postgresql≥ 42.4.0&&< 42.4.142.4.1org.postgresql:postgresql:42.4.1
☕Mavenorg.postgresql:postgresql≥ 42.3.0&&< 42.3.742.3.7org.postgresql:postgresql:42.3.7

Affected Products

3 products · 8 configurations
OS
debian linuxdebian
1 version
10.0
OS
fedorafedoraproject
2 versions
3536
Application
postgresql jdbc driverpostgresql
≥ 42.3.0 && < 42.3.7
2 versions
42.4.042.4.1
Exploits & PoCs
1

Research use only. For defensive security, authorized penetration testing, and academic research only. Never execute exploit code against systems without explicit written authorization.

Detection & mitigation playbook

Open-source dependency
  1. Detect

    Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for org.postgresql:postgresql, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.

  2. Fix

    Update org.postgresql:postgresql to 42.2.26 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2022-31197 is resolved across your whole dependency graph.

  3. Workarounds

    Until you can upgrade, make sure every query built from user input uses parameterised statements or a prepared-statement API rather than string concatenation, and reduce the database account's privileges so an injected query cannot read or alter data beyond what the feature needs.

Fixing This On Your OS

If you run this on a Linux distribution, patch through your package manager against the distro's own security advisory below — it tracks the exact backported fix for your release, which can ship on a different timeline (and sometimes a different severity) than the upstream project.

Red HatModerate

User applications that do not invoke the `ResultSet.refreshRow()` method are not impacted. Red Hat Fuse 7 is now in Maintenance Support Phase and details about its fix should be presented soon. However, Red Hat Fuse Online (Syndesis) does will not contain the fix for this flaw.

ProductFixed inAdvisory
Red Hat build of Quarkus 2.13.5postgresqlRHSA-2022:9023
Red Hat build of Quarkus 2.7.7see advisoryRHSA-2023:1006
Red Hat Enterprise Linux 9postgresql-jdbc-0:42.2.18-6.el9_1RHSA-2023:0318
Red Hat Fuse 7.11.1jdbc-postgresqlRHSA-2022:8652

Frequently Asked Questions

### Impact _What kind of vulnerability is it? Who is impacted?_ 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 ma
O3 Security · Impact-Aware SCA

Is CVE-2022-31197 in your dependencies?

Find it across Maven, including transitive dependencies.

CVE-2022-31197: postgresql — Fixed in 42.2.26