Repository navigation
Description
Integrity requirements
- I have read all the comments in the issue template and ensured that this issue meet the requirements.
- I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
- I provided the complete config and logs, rather than just providing the truncated parts based on my own judgment.
- I searched issues and did not find any similar issues.
- The problem can be successfully reproduced in the latest Release
Description
Two bugs in the XDNS client, both from #6718. Reproduced with v26.10.31 built from the tag (a4a3dff, go1.27.3); the three files involved are unchanged on main.
1. tcp:// resolvers send DNS messages without the two-byte length prefix
transport/internet/finalmask/xdns/resolver_tcp.go:127:
_ = binary.Write(r.conn, binary.BigEndian, len(p))
_, _ = r.conn.Write(p)binary.Write takes only fixed-size values. Given an int, it returns binary.Write: some values are not fixed-sized in type int and writes nothing, and the error is dropped. So each query goes out bare. A DNS server reads the random query ID as the length (RFC 1035 §4.2.2, RFC 7766 §8) and never answers. Against a miekg/dns TCP server, TCPResolver gets no reply within 5 s; a dns.Client{Net: "tcp"} asking the same question does get one. Reading answers (recv) handles the prefix correctly.
Possible fix, a single write as RFC 7766 §8 recommends:
b := make([]byte, 2+len(p))
binary.BigEndian.PutUint16(b, uint16(len(p)))
copy(b[2:], p)
_, _ = r.conn.Write(b)2. A domain with an empty label, or a label over 63 bytes, passes the config check and then panics the process
NewDomain (domain.go:82) rejects only .. and builds the name with dnsmessage.NewName(domain + "."), which checks only the total length. So t.example.com. (trailing dot), a., .a, ., an empty name and a 64-byte label are all accepted, by xray run -test too. On the first packet, client.go:152 calls common.Must2(msg.AppendPack(buf[:0])). Packing fails with zero length segment or segment length too long. The panic, in mKCP's updater goroutine, makes the process exit with status 2. Must2's own comment says that errors user input can cause must be handled.
NewDomain already computes ascii, err := idna.ToASCII(domain) and trims its dots, then never uses it. Building the name from ascii would make t.example.com. mean t.example.com. It would also fix IDN names, which now go on the wire as raw UTF-8: тест.рф. instead of xn--e1aybc.xn--p1ai., the name the zone is delegated under. An empty result and labels over 63 bytes would still need rejecting, for example:
ascii = strings.Trim(ascii, ".")
if ascii == "" {
return nil, errors.New("empty domain")
}
for _, label := range strings.Split(ascii, ".") {
if len(label) == 0 || len(label) > 63 {
return nil, errors.New("invalid domain")
}
}
name, err := dnsmessage.NewName(ascii + ".")The server calls NewDomain too, so for IDN names both sides would change together. If send handled the AppendPack error instead of using Must2, a bad name would drop the packet and the process would keep running.
With both changes applied, go test ./transport/internet/finalmask/xdns/ still passes. TCPResolver then gets the miekg/dns server's answer, and a client for t.example.com. sends its queries instead of panicking.
Reproduction Method
Only the client is needed. For bug 2, nothing has to listen on 127.0.0.1:10443 or :10053: the crash comes before anything is sent.
Bug 2:
- With the client config below,
xray run -test -c client.jsonprintsConfiguration OK. - Run
xray run -c client.json, thencurl --socks5 127.0.0.1:10808 http://127.0.0.1:9/. - Xray exits with status 2 and the panic in the client log below. A 64-byte label (
aaaa…a.example.com) givessegment length too longinstead. Witht.example.com, Xray keeps running.
Bug 1:
- In the same config, set
"names": ["t.example.com"]and"addrs": ["tcp://127.0.0.1:10053"]. - Run
nc -l 127.0.0.1 10053 | xxd | head, then start Xray and repeat the curl. - The stream starts with a DNS header (random ID, flags
0100, one question) and no length in front of it:
00000000: 82ef 0100 0001 0000 0000 0000 3f34 326f ............?42o
binary.Write alone, in Go:
var b bytes.Buffer
err := binary.Write(&b, binary.BigEndian, len("abc"))
// err: binary.Write: some values are not fixed-sized in type int; b.Len() == 0Client config
Details
{
"log": {"loglevel": "debug"},
"inbounds": [{
"listen": "127.0.0.1", "port": 10808, "protocol": "socks", "settings": {}
}],
"outbounds": [{
"protocol": "vless",
"settings": {"vnext": [{"address": "127.0.0.1", "port": 10443,
"users": [{"id": "07eaa124-df90-4d89-a29f-adea784450b2", "encryption": "none"}]}]},
"streamSettings": {
"network": "kcp",
"finalmask": {"udp": [{"type": "xdns", "settings": {
"domains": [{"names": ["t.example.com."]}],
"resolvers": [{"addrs": ["udp://127.0.0.1:10053"]}]
}}]}
}
}]
}
Server config
Not needed: both bugs are in the client and show before anything reaches a server.
Client log
Details
Xray 26.10.31 (Xray, Penetrates Everything.) a4a3dff (go1.27.3 darwin/arm64)
A unified platform for anti-censorship.
2026/11/08 11:36:15.214909 [Info] infra/conf/serial: Reading config: &{Name:client.json Format:json}
2026/11/08 11:36:15.215089 [Info] infra/conf: t.example.com.. 146
2026/11/08 11:36:15.215190 [Debug] app/log: Logger started
2026/11/08 11:36:15.215219 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:10808
2026/11/08 11:36:15.215650 [Info] transport/internet/tcp: listening tcp on 127.0.0.1:10808
2026/11/08 11:36:15.215663 [Warning] core: Xray 26.10.31 started
2026/11/08 11:36:16.736694 [Info] [1859862790] proxy/socks: TCP Connect request to tcp:127.0.0.1:9
2026/11/08 11:36:16.736751 from tcp:127.0.0.1:55210 accepted tcp:127.0.0.1:9
2026/11/08 11:36:16.736756 [Info] [1859862790] app/dispatcher: default route for tcp:127.0.0.1:9
2026/11/08 11:36:16.736793 [Info] [1859862790] transport/internet/kcp: dialing mKCP to udp:127.0.0.1:10443
2026/11/08 11:36:16.736808 [Debug] [1859862790] transport/internet: dialing to udp:127.0.0.1:10443
2026/11/08 11:36:16.737020 [Debug] [1859862790] transport/internet: dialing to udp:127.0.0.1:10053
2026/11/08 11:36:16.737461 [Info] transport/internet/kcp: #50963 creating connection to 127.0.0.1:10443
2026/11/08 11:36:16.737481 [Info] [1859862790] proxy/vless/outbound: tunneling request to tcp:127.0.0.1:9 via 127.0.0.1:10443
panic: packing Question: Name: zero length segment
goroutine 51 [running]:
github.com/xtls/xray-core/common.Must(...)
common/common.go:22
github.com/xtls/xray-core/common.Must2[...](...)
common/common.go:30
github.com/xtls/xray-core/transport/internet/finalmask/xdns.(*xdnsClient).send.func1({0x306727cb4998?, 0x3?, 0xf6?})
transport/internet/finalmask/xdns/client.go:152 +0x344
github.com/xtls/xray-core/transport/internet/finalmask/xdns.(*xdnsClient).send(0x306727c9e960, {0x3067279b0000, 0x76, 0x2000})
transport/internet/finalmask/xdns/client.go:189 +0x338
github.com/xtls/xray-core/transport/internet/finalmask/xdns.(*xdnsClient).WriteTo(0x306727c9e960, {0x3067279b0000, 0x76, 0x2000}, {0x306727cb4c28?, 0x104ae3bec?})
transport/internet/finalmask/xdns/client.go:376 +0xf0
github.com/xtls/xray-core/common/net.(*PacketConnWrapper).Write(0x106368cb0?, {0x3067279b0000?, 0x10030672799dc68?, 0x104ae6790?})
common/net/packet.go:15 +0x30
github.com/xtls/xray-core/transport/internet/kcp.(*SimpleSegmentWriter).Write(0x306727cac200, {0x1064c3330, 0x306727d9c000})
transport/internet/kcp/output.go:35 +0x190
github.com/xtls/xray-core/transport/internet/kcp.(*RetryableWriter).Write.func1()
transport/internet/kcp/output.go:51 +0x2c
github.com/xtls/xray-core/common/retry.(*retryer).On(0x306727da7d78, 0x306727da7d58)
common/retry/retry.go:27 +0xbc
github.com/xtls/xray-core/transport/internet/kcp.(*RetryableWriter).Write(0x1065e0888?, {0x1064c3330?, 0x306727d9c000?})
transport/internet/kcp/output.go:50 +0x68
github.com/xtls/xray-core/transport/internet/kcp.(*SendingWorker).Write(0x306727c450b0?, {0x1064c3330?, 0x306727d9c000?})
transport/internet/kcp/sending.go:287 +0x74
github.com/xtls/xray-core/transport/internet/kcp.(*SendingWindow).Flush.func1(0x30672799de28?)
transport/internet/kcp/sending.go:120 +0x9c
github.com/xtls/xray-core/transport/internet/kcp.(*SendingWindow).Visit(0x30672799de88?, 0x306727da7e50)
transport/internet/kcp/sending.go:92 +0x6c
github.com/xtls/xray-core/transport/internet/kcp.(*SendingWindow).Flush(0x306727c9aae0, 0x546f3c0?, 0x1?, 0x27ca2410?)
transport/internet/kcp/sending.go:106 +0x74
github.com/xtls/xray-core/transport/internet/kcp.(*SendingWorker).Flush(0x306727ca2460, 0x0)
transport/internet/kcp/sending.go:329 +0xcc
github.com/xtls/xray-core/transport/internet/kcp.(*Connection).flush(0x306727cae0e0)
transport/internet/kcp/connection.go:641 +0x188
github.com/xtls/xray-core/transport/internet/kcp.(*Connection).updateTask(...)
transport/internet/kcp/connection.go:528
github.com/xtls/xray-core/transport/internet/kcp.(*Updater).run(0x306727c9ab10)
transport/internet/kcp/connection.go:158 +0x94
created by github.com/xtls/xray-core/transport/internet/kcp.(*Updater).WakeUp in goroutine 42
transport/internet/kcp/connection.go:145 +0x78
Server log
None: no server is involved.
Activity
XDNS finalmask: Implement worker for TCP resolver (XTLS#7354)
XDNS finalmask: Implement worker for TCP resolver (XTLS#7354)