CVE-2022-40897: Setuptools Denial of Service Vulnerability

HIGH
Advisory Identifier: GHSA-r9hx-vwmv-q579
CVSS 7.5
CWE-1333
Published
Advisory Summary

CVE-2022-40897 is a HIGH (CVSS 7.5) denial of service vulnerability (CWE-1333: Inefficient Regular Expression Complexity) affecting Setuptools libraries in the PyPI ecosystem. The issue involves pypa/setuptools vulnerable to regular expression denial of service (redos). Remediation is available by upgrading affected packages to version 65.5.1.

CVE-2022-40897 at a Glance

CVE Identifier CVE-2022-40897
GHSA Identifier GHSA-r9hx-vwmv-q579
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-1333: Inefficient Regular Expression Complexity
Affected Product Setuptools
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.5

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

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

How to Fix CVE-2022-40897

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

setuptools fixed: 65.5.1
pip install setuptools>=65.5.1
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 setuptools

How to Check if You Are Affected

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

pip show setuptools

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

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

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-1333: Inefficient Regular Expression Complexity, where the product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential. In Setuptools, 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

Python Packaging Authority (PyPA)'s setuptools is a library designed to facilitate packaging Python projects. Setuptools version 65.5.0 and earlier could allow remote attackers to cause a denial of service by fetching malicious HTML from a PyPI package or custom PackageIndex page due to a vulnerable Regular Expression in `package_index`. This has been patched in version 65.5.1.

CVE-2022-40897 Affected Setuptools Versions

1 component(s)
Fixed Versions:
65.5.1
Product / Package Ecosystem Affected Versions Fixed Version
setuptools
PyPI
< 65.5.1
65.5.1

References

NVD — CVE-2022-40897 NVD
https://nvd.nist.gov/vuln/detail/CVE-2022-40897
Setuptools Source Repository REPOSITORY
https://github.com/pypa/setuptools/issues/3659
Security Fix Commit FIX COMMIT
https://github.com/pypa/setuptools/commit/43a9c9bfa6aa626ec2a22540bea28d2ca77964be
Setuptools Security Information SECURITY
https://setuptools.pypa.io/en/latest
Setuptools Security Information SECURITY
https://security.netapp.com/advisory/ntap-20240621-0006
Setuptools Security Information SECURITY
https://security.netapp.com/advisory/ntap-20230214-0001
pyup.io/vulnerabilities/cve... WEB
https://pyup.io/vulnerabilities/CVE-2022-40897/52495
pyup.io/posts/pyup-discover... WEB
https://pyup.io/posts/pyup-discovers-redos-vulnerabilities-in-top-python-packages
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/YNA2BAH2ACBZ4TVJZKFLCR7L23BG5C3H
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/ADES3NLOE5QJKBLGNZNI2RGVOSQXA37R
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/YNA2BAH2ACBZ4TVJZKFLCR7L23BG5C3H
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/ADES3NLOE5QJKBLGNZNI2RGVOSQXA37R
lists.debian.org/debian-lts-announce... WEB
https://lists.debian.org/debian-lts-announce/2024/09/msg00018.html
Setuptools Source Repository REPOSITORY
https://github.com/pypa/setuptools/compare/v65.5.0...v65.5.1
Setuptools Source Repository REPOSITORY
https://github.com/pypa/setuptools/blob/fe8a98e696241487ba6ac9f91faa38ade939ec5d/setuptools/package_index.py#L200
Setuptools Source Repository REPOSITORY
https://github.com/pypa/setuptools
Setuptools Source Repository REPOSITORY
https://github.com/pypa/advisory-database/tree/main/vulns/setuptools/PYSEC-2022-43012.yaml

Frequently Asked Questions

What is CVE-2022-40897?
CVE-2022-40897 is a security vulnerability in Setuptools involving pypa/setuptools vulnerable to Regular Expression Denial of Service (ReDoS) under CWE-1333: Inefficient Regular Expression Complexity.
Which Setuptools versions are affected?
Affected versions include releases prior to 65.5.1 across affected packages: setuptools.
What version fixes CVE-2022-40897?
Upgrading to 65.5.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is setuptools affected?
Yes, setuptools is affected in releases prior to 65.5.1. Upgrade your dependency to 65.5.1 or later.
What is the CVSS score of CVE-2022-40897?
CVE-2022-40897 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2022-40897?
CVE-2022-40897 is classified under CWE-1333: Inefficient Regular Expression Complexity (The product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential.).
How can I check PyPI dependencies for CVE-2022-40897?
Run the dependency tree command: 'pip show setuptools'. 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-r9hx-vwmv-q579",
  "modified" : "2025-11-04T19:37:00Z",
  "published" : "2022-12-23T00:30:23Z",
  "aliases" : [ "CVE-2022-40897" ],
  "summary" : "pypa/setuptools vulnerable to Regular Expression Denial of Service (ReDoS)",
  "details" : "Python Packaging Authority (PyPA)'s setuptools is a library designed to facilitate packaging Python projects. Setuptools version 65.5.0 and earlier could allow remote attackers to cause a denial of service by fetching malicious HTML from a PyPI package or custom PackageIndex page due to a vulnerable Regular Expression in `package_index`. This has been patched in version 65.5.1.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:L/SI:L/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "setuptools"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "65.5.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-40897"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/setuptools/issues/3659"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/setuptools/commit/43a9c9bfa6aa626ec2a22540bea28d2ca77964be"
  }, {
    "type" : "WEB",
    "url" : "https://setuptools.pypa.io/en/latest"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20240621-0006"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20230214-0001"
  }, {
    "type" : "WEB",
    "url" : "https://pyup.io/vulnerabilities/CVE-2022-40897/52495"
  }, {
    "type" : "WEB",
    "url" : "https://pyup.io/posts/pyup-discovers-redos-vulnerabilities-in-top-python-packages"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/YNA2BAH2ACBZ4TVJZKFLCR7L23BG5C3H"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/ADES3NLOE5QJKBLGNZNI2RGVOSQXA37R"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/YNA2BAH2ACBZ4TVJZKFLCR7L23BG5C3H"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/ADES3NLOE5QJKBLGNZNI2RGVOSQXA37R"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2024/09/msg00018.html"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/setuptools/compare/v65.5.0...v65.5.1"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/setuptools/blob/fe8a98e696241487ba6ac9f91faa38ade939ec5d/setuptools/package_index.py#L200"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/pypa/setuptools"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/setuptools/PYSEC-2022-43012.yaml"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1333" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-12-27T14:51:05Z",
    "nvd_published_at" : "2022-12-23T00:15:00Z"
  }
}