CVE-2022-31197
SQL Injection in ResultSet.refreshRow() with malicious column names in pgjdbc
Also known as BIT-postgresql-jdbc-driver-2022-31197, GHSA-r38f-c4h4-hqq2
Mitigation
- Upgrade org.postgresql:postgresql to one of 42.2.26, 42.4.1, 42.3.7 (or later in the same release line).
Who should check
- Projects that depend on Maven package org.postgresql:postgresql (< 42.2.26)
- Anyone running pgjdbc >= 42.2.0, < 42.2.26; >= 42.3.0, < 42.4.1
Vulnerability facts
- Affected
- org.postgresql:postgresql < 42.2.26
- Fixed in
- 42.2.26, 42.4.1, 42.3.7
- Exploited in the wild
- Not in CISA KEV
- Public exploit / PoC
- None known
- Remote exploitation
- Remote, login needed
- CVSS
- 7.1 (v3.1, CNA)CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:U/C:H/I:H/A:HOpen in CVSS calculator
Show all 8 CVSS metrics
- Attack vector: Network
- Attack complexity: High
- Privileges required: Low
- User interaction: Required
- Scope: Unchanged
- Confidentiality impact: High
- Integrity impact: High
- Availability impact: High
- EPSS
- 2.22% chance of exploitation in 30 days (percentile 83, 2026-11-26)
- CWE
- CWE-89
- Modified
Description
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.
Affected and fixed versions
| Package / product | Affected | Fixed | Source |
|---|---|---|---|
| Maven org.postgresql:postgresql | < 42.2.26 | 42.2.26, 42.4.1, 42.3.7 | osv |
| pgjdbc | >= 42.2.0, < 42.2.26; >= 42.3.0, < 42.4.1 | — | cvelist |
Check your systems with an agent
Paste this into Claude Code, Cursor or another coding agent. It only reads; it changes nothing.
Check whether anything I run is affected by CVE-2022-31197. Work read-only: do not install, upgrade, delete or change anything. Details: https://flawdb.com/CVE-2022-31197.md Affected: org.postgresql:postgresql < 42.2.26 Fixed in: 42.2.26, 42.4.1, 42.3.7 Steps: 1. Search this machine and project for org.postgresql:postgresql (Maven), pgjdbc: dependency manifests and lockfiles, installed packages, container images and running services. 2. For each match, note the installed version and whether it is inside the affected range. 3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
References
Vendor advisories
- https://github.com/pgjdbc/pgjdbc/security/advisories/GHSA-r38f-c4h4-hqq2
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/I6WHUADTZBBQLVHO4YG4XCWDGWBT4LRP/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/UTFE6SV33P5YYU2GNTQZQKQRVR3GYE4S/
- https://nvd.nist.gov/vuln/detail/CVE-2022-31197
Other
- https://lists.debian.org/debian-lts-announce/2022/10/msg00009.html
- https://lists.debian.org/debian-lts-announce/2024/12/msg00017.html
- https://github.com/pgjdbc/pgjdbc
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/I6WHUADTZBBQLVHO4YG4XCWDGWBT4LRP
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/UTFE6SV33P5YYU2GNTQZQKQRVR3GYE4S
- https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/I6WHUADTZBBQLVHO4YG4XCWDGWBT4LRP
- https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/UTFE6SV33P5YYU2GNTQZQKQRVR3GYE4S
FAQ
Is CVE-2022-31197 being exploited?
There is no confirmed exploitation: CVE-2022-31197 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 2.22% chance of exploitation in the next 30 days (as of 2026-11-26).
How serious is CVE-2022-31197?
High: CVSS 7.1 (v3.1, scored by CNA). Remote, login needed. A user has to take an action, such as opening a link, for the attack to work. The attack needs conditions outside the attacker's control, which makes it harder.
Which versions are affected by CVE-2022-31197?
org.postgresql:postgresql < 42.2.26.
Is there a fix for CVE-2022-31197?
Yes. Fixed in 42.2.26, 42.4.1, 42.3.7. Upgrade org.postgresql:postgresql to one of 42.2.26, 42.4.1, 42.3.7 (or later in the same release line).
How do I check if I'm affected by CVE-2022-31197?
Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.