CVE-2021-45958: Ujson UltraJSON Vulnerable To Out-of-bounds Write Vulnerability

MODERATE
Advisory Identifier: GHSA-fh56-85cw-5pq6
CVSS 5.5
CWE-787
Published
Advisory Summary

CVE-2021-45958 is a MODERATE (CVSS 5.5) ultrajson vulnerable to out-of-bounds write vulnerability (CWE-787: Out-of-bounds Write) affecting Ujson libraries in the PyPI ecosystem. The issue involves ultrajson vulnerable to out-of-bounds write. Remediation is available by upgrading affected packages to version 5.2.0.

CVE-2021-45958 at a Glance

CVE Identifier CVE-2021-45958
GHSA Identifier GHSA-fh56-85cw-5pq6
Severity MODERATE
CVSS v3.1 Base Score 5.5
CWE Classification CWE-787: Out-of-bounds Write
Affected Product Ujson
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 5.5

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

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

How to Fix CVE-2021-45958

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

ujson fixed: 5.2.0
pip install ujson>=5.2.0
Verify Direct and Transitive Dependencies

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

pip show ujson

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2021-45958, inspect your installed packages using pip:

pip show ujson

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

Note: The pip show ujson command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-787: Out-of-bounds Write, where the product writes data past the end, or before the beginning, of the intended buffer. In Ujson, 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

UltraJSON (aka ujson) 1.34 through 5.1.0 has a stack-based buffer overflow in Buffer_AppendIndentUnchecked (called from encode).

CVE-2021-45958 Affected Ujson Versions

1 component(s)
Fixed Versions:
5.2.0
Product / Package Ecosystem Affected Versions Fixed Version
ujson
PyPI
≥ 1.34
< 5.2.0
5.2.0

References

NVD — CVE-2021-45958 NVD
https://nvd.nist.gov/vuln/detail/CVE-2021-45958
Ujson Source Repository REPOSITORY
https://github.com/ultrajson/ultrajson/issues/501
Ujson Source Repository REPOSITORY
https://github.com/ultrajson/ultrajson/issues/502#issuecomment-1031747284
Ujson Source Repository REPOSITORY
https://github.com/ultrajson/ultrajson/pull/504
Ujson Source Repository REPOSITORY
https://github.com/ultrajson/ultrajson/pull/519
bugs.chromium.org/p/oss-fuzz/issues/d... WEB
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=36009
GitHub Advisory / Wiki ADVISORY
https://github.com/advisories/GHSA-fh56-85cw-5pq6
Ujson Source Repository REPOSITORY
https://github.com/google/oss-fuzz-vulns/blob/main/vulns/ujson/OSV-2021-955.yaml
Ujson Source Repository REPOSITORY
https://github.com/pypa/advisory-database/tree/main/vulns/ujson/PYSEC-2022-25.yaml
Ujson Source Repository REPOSITORY
https://github.com/ultrajson/ultrajson
lists.debian.org/debian-lts-announce... WEB
https://lists.debian.org/debian-lts-announce/2022/02/msg00023.html
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/CN7W3GOXALINKFUUE7ICQIC2EF5HNKUQ
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/NAU5N4A7EUK2AMUCOLYDD5ARXAJYZBD2
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/O6JUWQTJLA2CMG4CJN7DCUVSOXLZIIXL
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/ULX35TSWLBBIMEH44MUORPXYYRZKEDC6

Frequently Asked Questions

What is CVE-2021-45958?
CVE-2021-45958 is a security vulnerability in Ujson involving UltraJSON vulnerable to Out-of-bounds Write under CWE-787: Out-of-bounds Write.
Which Ujson versions are affected?
Affected versions include releases prior to 5.2.0 across affected packages: ujson.
What version fixes CVE-2021-45958?
Upgrading to 5.2.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is ujson affected?
Yes, ujson is affected in releases prior to 5.2.0. Upgrade your dependency to 5.2.0 or later.
What is the CVSS score of CVE-2021-45958?
CVE-2021-45958 has a CVSS v3.1 base score of 5.5 (MODERATE) with vector string CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2021-45958?
CVE-2021-45958 is classified under CWE-787: Out-of-bounds Write (The product writes data past the end, or before the beginning, of the intended buffer.).
How can I check PyPI dependencies for CVE-2021-45958?
Run the dependency tree command: 'pip show ujson'. 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-fh56-85cw-5pq6",
  "modified" : "2024-11-18T22:47:32Z",
  "published" : "2022-01-21T23:27:45Z",
  "aliases" : [ "CVE-2021-45958" ],
  "summary" : "UltraJSON vulnerable to Out-of-bounds Write",
  "details" : "UltraJSON (aka ujson) 1.34 through 5.1.0 has a stack-based buffer overflow in Buffer_AppendIndentUnchecked (called from encode).",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "ujson"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.34"
      }, {
        "fixed" : "5.2.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-45958"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ultrajson/ultrajson/issues/501"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ultrajson/ultrajson/issues/502#issuecomment-1031747284"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ultrajson/ultrajson/pull/504"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ultrajson/ultrajson/pull/519"
  }, {
    "type" : "WEB",
    "url" : "https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=36009"
  }, {
    "type" : "ADVISORY",
    "url" : "https://github.com/advisories/GHSA-fh56-85cw-5pq6"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/google/oss-fuzz-vulns/blob/main/vulns/ujson/OSV-2021-955.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/ujson/PYSEC-2022-25.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/ultrajson/ultrajson"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2022/02/msg00023.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/CN7W3GOXALINKFUUE7ICQIC2EF5HNKUQ"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/NAU5N4A7EUK2AMUCOLYDD5ARXAJYZBD2"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/O6JUWQTJLA2CMG4CJN7DCUVSOXLZIIXL"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/ULX35TSWLBBIMEH44MUORPXYYRZKEDC6"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-787" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-01-12T19:29:48Z",
    "nvd_published_at" : "2022-01-01T00:15:00Z"
  }
}