SQL Injection Vulnerability in PostgreSQL JDBC Driver (libpgjava) - CVE-2022-31197
Summary
UBUNTU-CVE-2022-31197: PostgreSQL JDBC Driver (PgJDBC for short) allows Java programs to connect to a PostgreSQL database using standard, database independent Java code. Affects libpgjava versions 9.2-1002-1. No fix is published. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The PostgreSQL JDBC Driver, commonly referred to as PgJDBC, is a crucial library that enables Java applications to connect to PostgreSQL databases using standard Java code. It is widely used in various applications for database interactions. The driver provides a set of functionalities that allow developers to execute SQL queries, retrieve results, and manage database connections efficiently. However, a significant vulnerability has been identified in the implementation of the java.sql.ResultRow.refreshRow() method, which could expose applications to SQL injection attacks if not addressed promptly.
Vulnerability Detail
The vulnerability arises from the PgJDBC implementation of the refreshRow() method, which fails to properly escape column names. This oversight allows an attacker to inject malicious SQL commands by crafting a column name that includes a statement terminator, such as a semicolon (;). If a user application invokes this method on a ResultSet that queries a database controlled by an attacker, it could lead to the execution of unauthorized SQL commands as the application's JDBC user. This vulnerability is particularly concerning for applications running with elevated privileges, as it could allow attackers to execute commands in the context of a privileged user.
How To Fix
No fixed version is published for this vulnerability.
Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. Scan free →
Workaround
There are no known workarounds for this vulnerability. The best course of action is to apply the available patches as soon as possible.
Conclusion
The CVE-2022-31197 vulnerability in the PostgreSQL JDBC Driver poses a serious risk of SQL injection attacks due to improper handling of column names. Users are strongly advised to upgrade to the patched versions to secure their applications against potential exploitation. Regular monitoring for vulnerabilities using tools like Vulert can help maintain application security.
See every vulnerability recorded for libpgjava →
FAQ
CVE-2022-31197 is a vulnerability in the PostgreSQL JDBC Driver that allows for SQL injection through the improper handling of column names in the refreshRow() method.
You can check if your application is affected by using the Vulert playground, which allows you to monitor and alert for open-source vulnerabilities without needing to sign up.
If exploited, this vulnerability could allow attackers to execute unauthorized SQL commands, potentially compromising sensitive data and application integrity.
Yes, patched versions of the PostgreSQL JDBC Driver are available. Users should upgrade to versions 42.2.26 or 42.4.1.
While there are no workarounds available, it is crucial to prioritize the upgrade to mitigate the risk associated with this vulnerability.
Related vulnerabilities
Recent vulnerabilities recorded for libpgjava.