# CVE-2023-40217: Security feature bypass in n/a

> Attackers can bypass TLS client certificate authentication on Python servers by exploiting a race condition in socket closure, allowing unauthenticated data access.

- **Severity:** Medium 5.3 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 25 Aug 2023
- **Updated:** 3 Nov 2025
- **Also known as:** ALPINE-CVE-2023-40217, ALSA-2023:5456, ALSA-2023:5462, ALSA-2023:5463, ALSA-2023:5994, ALSA-2023:5997, ALSA-2023:5998, AZL-109668, AZL-31170, BIT-libpython-2023-40217, BIT-python-2023-40217, BIT-python-min-2023-40217, CLEANSTART-2026-HA84441, CLSA-2023-1701971229, CLSA-2023-1701971295, CLSA-2023-1701971396, CLSA-2023-1701971558, CLSA-2024-1705079922, CLSA-2024-1705080095, DEBIAN-CVE-2023-40217, GHSA-4j9r-82g6-9mj3, OESA-2023-1677, PSF-2023-8, RHSA-2023:5456, RHSA-2023:5462, RHSA-2023:5463, RHSA-2023:5472, RHSA-2023:5528, RHSA-2023:5531, RHSA-2023:5990, RHSA-2023:5991, RHSA-2023:5992, RHSA-2023:5993, RHSA-2023:5994, RHSA-2023:5995, RHSA-2023:5996, RHSA-2023:5997, RHSA-2023:5998, RHSA-2023:6068, RHSA-2023:6069, RHSA-2023:6290, RHSA-2023:6823, RHSA-2023:6885, RLSA-2023:5463, RLSA-2023:5994, RLSA-2023:5997, RLSA-2023:5998, SUSE-SU-2023:3708-1, SUSE-SU-2023:3730-1, SUSE-SU-2023:3731-1, SUSE-SU-2023:3804-1, SUSE-SU-2023:3824-1, SUSE-SU-2023:3828-1, SUSE-SU-2023:3828-2, SUSE-SU-2023:3933-1, UBUNTU-CVE-2023-40217, USN-6513-2, openSUSE-SU-2024:13193-1, openSUSE-SU-2024:13201-1, openSUSE-SU-2024:13215-1, openSUSE-SU-2024:13219-1, openSUSE-SU-2024:13236-1, openSUSE-SU-2024:13248-1, openSUSE-SU-2024:13890-1

## What is CVE-2023-40217?

CVE-2023-40217 is a medium-severity vulnerability in Python Python, published on 25 Aug 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

An issue was discovered in Python before 3.8.18, 3.9.x before 3.9.18, 3.10.x before 3.10.13, and 3.11.x before 3.11.5. It primarily affects servers (such as HTTP servers) that use TLS client authentication. If a TLS server-side socket is created, receives data into the socket buffer, and then is closed quickly, there is a brief window where the SSLSocket instance will detect the socket as "not connected" and won't initiate a handshake, but buffered data will still be readable from the socket buffer. This data will not be authenticated if the server-side TLS peer is expecting client certificate authentication, and is indistinguishable from valid TLS stream data. Data is limited in size to the amount that will fit in the buffer. (The TLS connection cannot directly be used for data exfiltration because the vulnerable code path requires that the connection be closed on initialization of the SSLSocket.)

## Which versions are affected by CVE-2023-40217?

3 open source packages ship an affected version, including libpython, python and python-min. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `libpython` | Bitnami | All versions | 3.8.18, 3.9.18, 3.10.13, 3.11.5 |
| `python` | Bitnami | All versions | 3.8.18, 3.9.18, 3.10.13, 3.11.5 |
| `python-min` | Bitnami | All versions | 3.8.18, 3.9.18, 3.10.13, 3.11.5 |
| `babel` | AlmaLinux:8 | All versions | 2.5.1-10.module_el8.6.0+2781+fed64c13 |
| `platform-python` | AlmaLinux:8 | All versions | 3.6.8-51.el8_8.2.alma.1 |
| `platform-python-debug` | AlmaLinux:8 | All versions | 3.6.8-51.el8_8.2.alma.1 |
| `platform-python-devel` | AlmaLinux:8 | All versions | 3.6.8-51.el8_8.2.alma.1 |
| `python-nose-docs` | AlmaLinux:8 | All versions | 1.3.7-31.module_el8.6.0+2781+fed64c13 |
| `python-psycopg2-doc` | AlmaLinux:8 | All versions | 2.7.5-7.module_el8.6.0+2781+fed64c13 |
| `python-psycopg2-doc` | AlmaLinux:8 | All versions | 2.7.5-7.module_el8.6.0+3162+01a09e5a |
| `python-sqlalchemy-doc` | AlmaLinux:8 | All versions | 1.3.2-2.module_el8.6.0+2781+fed64c13 |
| `python2` | AlmaLinux:8 | All versions | 2.7.18-13.module_el8.8.0+3663+627ce7bb.2.alma.1 |
| `python2-Cython` | AlmaLinux:8 | All versions | 0.28.1-7.module_el8.6.0+2781+fed64c13 |
| `python2-Cython` | AlmaLinux:8 | All versions | 0.28.1-7.module_el8.6.0+3162+01a09e5a |
| `python2-PyMySQL` | AlmaLinux:8 | All versions | 0.8.0-10.module_el8.6.0+2781+fed64c13 |
| `python2-attrs` | AlmaLinux:8 | All versions | 17.4.0-10.module_el8.6.0+2781+fed64c13 |
| `python2-babel` | AlmaLinux:8 | All versions | 2.5.1-10.module_el8.6.0+2781+fed64c13 |
| `python2-backports` | AlmaLinux:8 | All versions | 1.0-16.module_el8.6.0+2781+fed64c13 |
| `python2-backports` | AlmaLinux:8 | All versions | 1.0-16.module_el8.6.0+3162+01a09e5a |
| `python2-backports-ssl_match_hostname` | AlmaLinux:8 | All versions | 3.5.0.1-12.module_el8.6.0+2781+fed64c13 |
| `python2-bson` | AlmaLinux:8 | All versions | 3.7.0-1.module_el8.6.0+2781+fed64c13 |
| `python2-bson` | AlmaLinux:8 | All versions | 3.7.0-1.module_el8.6.0+3162+01a09e5a |
| `python2-chardet` | AlmaLinux:8 | All versions | 3.0.4-10.module_el8.6.0+2781+fed64c13 |
| `python2-coverage` | AlmaLinux:8 | All versions | 4.5.1-4.module_el8.6.0+2781+fed64c13 |
| `python2-coverage` | AlmaLinux:8 | All versions | 4.5.1-4.module_el8.6.0+3162+01a09e5a |
| `python2-debug` | AlmaLinux:8 | All versions | 2.7.18-13.module_el8.8.0+3663+627ce7bb.2.alma.1 |
| `python2-devel` | AlmaLinux:8 | All versions | 2.7.18-13.module_el8.8.0+3663+627ce7bb.2.alma.1 |
| `python2-dns` | AlmaLinux:8 | All versions | 1.15.0-10.module_el8.6.0+2781+fed64c13 |
| `python2-docs` | AlmaLinux:8 | All versions | 2.7.16-2.module_el8.6.0+2781+fed64c13 |
| `python2-docs-info` | AlmaLinux:8 | All versions | 2.7.16-2.module_el8.6.0+2781+fed64c13 |
| `python2-docutils` | AlmaLinux:8 | All versions | 0.14-12.module_el8.6.0+2781+fed64c13 |
| `python2-funcsigs` | AlmaLinux:8 | All versions | 1.0.2-13.module_el8.6.0+2781+fed64c13 |
| `python2-idna` | AlmaLinux:8 | All versions | 2.5-7.module_el8.6.0+2781+fed64c13 |
| `python2-ipaddress` | AlmaLinux:8 | All versions | 1.0.18-6.module_el8.6.0+2781+fed64c13 |
| `python2-jinja2` | AlmaLinux:8 | All versions | 2.10-9.module_el8.6.0+2781+fed64c13 |
| `python2-libs` | AlmaLinux:8 | All versions | 2.7.18-13.module_el8.8.0+3663+627ce7bb.2.alma.1 |
| `python2-lxml` | AlmaLinux:8 | All versions | 4.2.3-6.module_el8.6.0+2781+fed64c13 |
| `python2-lxml` | AlmaLinux:8 | All versions | 4.2.3-6.module_el8.6.0+3162+01a09e5a |
| `python2-markupsafe` | AlmaLinux:8 | All versions | 0.23-19.module_el8.6.0+2781+fed64c13 |
| `python2-markupsafe` | AlmaLinux:8 | All versions | 0.23-19.module_el8.6.0+3162+01a09e5a |

Products: Python Python.

## How do I fix CVE-2023-40217?

Upgrade libpython to a fixed version for your release line: 3.8.18, 3.9.18, 3.10.13 or 3.11.5.

## Is CVE-2023-40217 being exploited?

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

## Other vulnerabilities in Python Python

- [CVE-2008-5031](https://insights.sbomify.com/CVE-2008-5031/): Integer overflow in n/a (critical 10.0)
- [CVE-2014-4650](https://insights.sbomify.com/CVE-2014-4650/): Path traversal in n/a (critical 9.8)
- [CVE-2016-5636](https://insights.sbomify.com/CVE-2016-5636/): Integer overflow in n/a (critical 9.8)
- [CVE-2007-4559](https://insights.sbomify.com/CVE-2007-4559/): Path traversal in n/a (critical 9.8)
- [CVE-2017-17522](https://insights.sbomify.com/CVE-2017-17522/): Command injection in n/a (high 8.8)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2023-40217 and fix it if it is affected.

What it is: CVE-2023-40217 is a medium-severity vulnerability in Python Python, published on 25 Aug 2023. 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-2023-40217 in the wild and no public exploit code.

Affected packages and fixed versions:
- libpython (Bitnami): affected all versions; fixed in 3.8.18, 3.9.18, 3.10.13, 3.11.5
- python (Bitnami): affected all versions; fixed in 3.8.18, 3.9.18, 3.10.13, 3.11.5
- python-min (Bitnami): affected all versions; fixed in 3.8.18, 3.9.18, 3.10.13, 3.11.5

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-2023-40217/ (Markdown: https://insights.sbomify.com/CVE-2023-40217/index.md)
```

## Sources

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

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