# CVE-2024-26130: cryptography NULL pointer dereference with pkcs12.serialize_key_and_certificates when called with a non-matching certificate and private key and an hmac_hash override

> A NULL pointer dereference in the Python cryptography library causes a crash when serializing mismatched keys with specific HMAC settings.

- **Severity:** High 7.5 (`CVSS:3.1/AV:N/AC:L/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:** 21 Feb 2024
- **Updated:** 14 Aug 2024
- **Also known as:** ALSA-2025:15608, BELL-CVE-2024-26130, DEBIAN-CVE-2024-26130, ECHO-c0e9-a477-5a84, GHSA-6vqw-3v5j-54x4, PYSEC-2024-225, RHSA-2025:15608, RLSA-2025:15608, ROOT-APP-PYPI-CVE-2024-26130, SUSE-SU-2024:0763-1, SUSE-SU-2024:2138-1, UBUNTU-CVE-2024-26130, USN-6673-3, openSUSE-SU-2024:13710-1

## What is CVE-2024-26130?

CVE-2024-26130 is a high-severity vulnerability in pyca cryptography, published on 21 Feb 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

cryptography is a package designed to expose cryptographic primitives and recipes to Python developers. Starting in version 38.0.0 and prior to version 42.0.4, if `pkcs12.serialize_key_and_certificates` is called with both a certificate whose public key did not match the provided private key and an `encryption_algorithm` with `hmac_hash` set (via `PrivateFormat.PKCS12.encryption_builder().hmac_hash(...)`, then a NULL pointer dereference would occur, crashing the Python process. This has been resolved in version 42.0.4, the first version in which a `ValueError` is properly raised.

Weakness: CWE-476 (NULL Pointer Dereference)

## Which versions are affected by CVE-2024-26130?

3 open source packages ship an affected version, including cryptography. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `cryptography` | PyPI | From 38.0.0 | 42.0.4 |
| `cryptography` | PyPI | From 38.0.0 | 42.0.4 |
| `cryptography` | PyPI | From 38.0.0 | 42.0.4 |
| `python3.12-cryptography` | AlmaLinux:9 | All versions | 41.0.7-2.el9_6.1 |
| `python3.12-cryptography` | Red Hat:enterprise_linux:9::appstream | All versions | 0:41.0.7-2.el9_6.1 |
| `python3.12-cryptography-debuginfo` | Red Hat:enterprise_linux:9::appstream | All versions | 0:41.0.7-2.el9_6.1 |
| `python3.12-cryptography-debugsource` | Red Hat:enterprise_linux:9::appstream | All versions | 0:41.0.7-2.el9_6.1 |
| `python3.12-cryptography` | Rocky Linux:9 | All versions | 0:41.0.7-2.el9_6.1 |
| `python-cryptography` | SUSE:Linux Enterprise Module for Python 3 15 SP5 | All versions | 41.0.3-150400.16.15.1 |
| `python-cryptography` | SUSE:Linux Enterprise Module for Python 3 15 SP6 | All versions | 41.0.3-150600.23.3.1 |
| `python-cryptography` | openSUSE:Leap 15.5 | All versions | 41.0.3-150400.16.15.1 |
| `python-cryptography` | openSUSE:Leap 15.6 | All versions | 41.0.3-150600.23.3.1 |
| `python-cryptography` | openSUSE:Tumbleweed | All versions | 42.0.4-1.1 |

Products: Cryptography.io Cryptography.

## How do I fix CVE-2024-26130?

Upgrade cryptography to 42.0.4 or later.

## Is CVE-2024-26130 being exploited?

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

## Other vulnerabilities in pyca cryptography

- [CVE-2020-36242](https://insights.sbomify.com/CVE-2020-36242/): PyCA Cryptography symmetrically encrypting large values can lead to integer overflow (critical 9.1)
- [CVE-2026-26007](https://insights.sbomify.com/CVE-2026-26007/): cryptography Subgroup Attack Due to Missing Subgroup Validation for SECT Curves (high 8.2)
- [CVE-2023-38325](https://insights.sbomify.com/CVE-2023-38325/): cryptography mishandles SSH certificates (high 7.5)
- [CVE-2026-39892](https://insights.sbomify.com/CVE-2026-39892/): cryptography has a buffer overflow if non-contiguous buffers were passed to APIs (medium 6.9)
- [CVE-2023-49083](https://insights.sbomify.com/CVE-2023-49083/): cryptography vulnerable to NULL-dereference when loading PKCS7 certificates (medium 5.9)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-26130 and fix it if it is affected.

What it is: CVE-2024-26130 is a high-severity vulnerability in pyca cryptography, published on 21 Feb 2024. 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-2024-26130 in the wild and no public exploit code.

Affected packages and fixed versions:
- cryptography (PyPI): affected from 38.0.0; fixed in 42.0.4
- cryptography (PyPI): affected from 38.0.0; fixed in 42.0.4
- cryptography (PyPI): affected from 38.0.0; fixed in 42.0.4

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

## Sources

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

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