# CVE-2022-40897: pypa/setuptools vulnerable to Regular Expression Denial of Service (ReDoS)

> Remote attackers can cause denial of service in Python setuptools via crafted HTML in packages or custom PackageIndex pages due to ReDoS.

- **Severity:** Medium 5.9 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 22 Dec 2022
- **Updated:** 4 Nov 2025
- **Also known as:** ALSA-2023:0835, ALSA-2023:0952, AZL-60207, BIT-setuptools-2022-40897, CLSA-2026-1774916703, CLSA-2026-1789379973, CLSA-2026-1791500181, CLSA-2026-1791500952, DEBIAN-CVE-2022-40897, GHSA-r9hx-vwmv-q579, MGASA-2023-0219, MINI-4fpq-grg3-6c6c, OESA-2023-1004, PYSEC-2022-43012, RHSA-2023:0835, RHSA-2023:0952, RHSA-2023:7395, RHSA-2024:4421, RLSA-2023:0835, RLSA-2023:0952, ROOT-APP-PYPI-CVE-2022-40897, SUSE-SU-2023:0091-1, SUSE-SU-2023:0093-1, SUSE-SU-2023:0094-1, SUSE-SU-2023:0159-1, SUSE-SU-2023:0202-1, SUSE-SU-2023:0223-1, SUSE-SU-2023:0402-1, SUSE-SU-2023:0403-1, SUSE-SU-2023:4517-1, SUSE-SU-2024:2435-1, UBUNTU-CVE-2022-40897, USN-5817-1

## What is CVE-2022-40897?

CVE-2022-40897 is a medium-severity denial of service vulnerability in n/a, published on 22 Dec 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Python Packaging Authority (PyPA) setuptools before 65.5.1 allows remote attackers to cause a denial of service via HTML in a crafted package or custom PackageIndex page. There is a Regular Expression Denial of Service (ReDoS) in package_index.py.

Weakness: CWE-1333 (Inefficient Regular Expression Complexity)

## Which versions are affected by CVE-2022-40897?

4 open source packages ship an affected version, including setuptools. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `setuptools` | Bitnami | All versions | 65.5.1 |
| `setuptools` | PyPI | All versions | 65.5.1 |
| `setuptools` | PyPI | All versions | 65.5.1 |
| `setuptools` | PyPI | All versions | 65.5.1 |
| `platform-python-setuptools` | AlmaLinux:8 | All versions | 39.2.0-6.el8_7.1 |
| `python3-setuptools` | AlmaLinux:8 | All versions | 39.2.0-6.el8_7.1 |
| `python3-setuptools-wheel` | AlmaLinux:8 | All versions | 39.2.0-6.el8_7.1 |
| `python3-setuptools` | AlmaLinux:9 | All versions | 53.0.0-10.el9_1.1 |
| `python3-setuptools-wheel` | AlmaLinux:9 | All versions | 53.0.0-10.el9_1.1 |
| `platform-python-setuptools` | Red Hat:enterprise_linux:8::baseos | All versions | 0:39.2.0-6.el8_7.1 |
| `python-setuptools` | Red Hat:enterprise_linux:8::baseos | All versions | 0:39.2.0-6.el8_7.1 |
| `python3-setuptools` | Red Hat:enterprise_linux:8::baseos | All versions | 0:39.2.0-6.el8_7.1 |
| `python3-setuptools-wheel` | Red Hat:enterprise_linux:8::baseos | All versions | 0:39.2.0-6.el8_7.1 |
| `python-setuptools` | Red Hat:enterprise_linux:9::baseos | All versions | 0:53.0.0-10.el9_1.1 |
| `python3-setuptools` | Red Hat:enterprise_linux:9::baseos | All versions | 0:53.0.0-10.el9_1.1 |
| `python3-setuptools-wheel` | Red Hat:enterprise_linux:9::baseos | All versions | 0:53.0.0-10.el9_1.1 |
| `platform-python-setuptools` | Red Hat:rhel_eus:8.6::baseos | All versions | 0:39.2.0-7.el8_6 |
| `python-setuptools` | Red Hat:rhel_eus:8.6::baseos | All versions | 0:39.2.0-7.el8_6 |
| `python3-setuptools` | Red Hat:rhel_eus:8.6::baseos | All versions | 0:39.2.0-7.el8_6 |
| `python3-setuptools-wheel` | Red Hat:rhel_eus:8.6::baseos | All versions | 0:39.2.0-7.el8_6 |
| `PyYAML` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:5.4.1-1.module+el8.5.0+10613+59a13ec4 |
| `PyYAML-debugsource` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:5.4.1-1.module+el8.5.0+10613+59a13ec4 |
| `mod_wsgi` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:4.7.1-5.module+el8.7.0+16654+645aad7f |
| `numpy` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:1.19.4-3.module+el8.5.0+12204+54860423 |
| `numpy-debugsource` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:1.19.4-3.module+el8.5.0+12204+54860423 |
| `python-PyMySQL` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:0.10.1-2.module+el8.4.0+9822+20bf1249 |
| `python-cffi` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:1.14.3-2.module+el8.4.0+9822+20bf1249 |
| `python-cffi-debugsource` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:1.14.3-2.module+el8.4.0+9822+20bf1249 |
| `python-chardet` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:3.0.4-19.module+el8.4.0+9822+20bf1249 |
| `python-cryptography` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:3.3.1-2.module+el8.4.0+9822+20bf1249 |
| `python-cryptography-debugsource` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:3.3.1-2.module+el8.4.0+9822+20bf1249 |
| `python-idna` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:2.10-3.module+el8.4.0+9822+20bf1249 |
| `python-lxml` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:4.6.5-1.module+el8.6.0+13933+9cf0c87c |
| `python-lxml-debugsource` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:4.6.5-1.module+el8.6.0+13933+9cf0c87c |
| `python-ply` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:3.11-10.module+el8.4.0+9822+20bf1249 |
| `python-psutil` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:5.8.0-4.module+el8.4.0+9822+20bf1249 |
| `python-psutil-debugsource` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:5.8.0-4.module+el8.4.0+9822+20bf1249 |
| `python-psycopg2` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:2.8.6-2.module+el8.4.0+9822+20bf1249 |
| `python-psycopg2-debugsource` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:2.8.6-2.module+el8.4.0+9822+20bf1249 |
| `python-pycparser` | Red Hat:rhel_eus:8.8::appstream | All versions | 0:2.20-3.module+el8.4.0+9822+20bf1249 |

Products: Python Setuptools.

## How do I fix CVE-2022-40897?

Upgrade setuptools to 65.5.1 or later.

## Is CVE-2022-40897 being exploited?

There is no known exploitation of CVE-2022-40897 in the wild and no public exploit code.

## Other vulnerabilities in n/a

- [CVE-2013-1633](https://insights.sbomify.com/CVE-2013-1633/): Setuptools vulnerable to Man-in-the-middle attacks (medium 6.8)
- [CVE-2026-59890](https://insights.sbomify.com/CVE-2026-59890/): setuptools: MANIFEST.in exclusion bypass in sdist via Unicode normalization collision (NFC/NFD) on macOS APFS/HFS+ (medium 6.1)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2022-40897 and fix it if it is affected.

What it is: CVE-2022-40897 is a medium-severity denial of service vulnerability in n/a, published on 22 Dec 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2022-40897 in the wild and no public exploit code.

Affected packages and fixed versions:
- setuptools (Bitnami): affected all versions; fixed in 65.5.1
- setuptools (PyPI): affected all versions; fixed in 65.5.1
- setuptools (PyPI): affected all versions; fixed in 65.5.1
- setuptools (PyPI): affected all versions; fixed in 65.5.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2022-40897/ (Markdown: https://insights.sbomify.com/CVE-2022-40897/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2022-40897
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2022-40897
- OSV: https://osv.dev/vulnerability/CVE-2022-40897

---
From sbomify Insights: https://insights.sbomify.com/CVE-2022-40897/
Summaries are generated and may contain mistakes; the official description above is the record.
