TLS sniffer does not read SNI from a ClientHello split across TLS records (and large post-quantum ClientHellos make #7286's case more common)
Maintainers usually reply within 1 day
@Fangliding is already working on this.
Since Dec 1, 2026.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 57/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go
- Domain
- networking
Research direction
Read common/protocol/tls/sniff.go around SniffTLS and ReadClientHello, then inspect app/dispatcher/default.go:417-427 to understand how incomplete data is handled. Reproduce with ClientHellos split across TLS records and with a valid record arriving in several reads. Done when both shapes preserve SNI for domain routing and the accumulated handshake stays within the existing 8 KiB payload buffer.
Written by the indexing model from the issue text.
Description
Follow-up to #7286. I understand from that discussion that the sniffer is best-effort and is not meant to be a firewall, and I'm not asking for it to block anything. This issue is about valid ClientHellos produced by normal clients, which the sniffer currently can't read, so domain routing rules don't apply to them.
Version: v26.11.9 (676eaf66f8f0), official Linux x86-64 release. Line numbers below are from that tag. On main (919d0ae8eb54, 2026-11-30) sniff.go is unchanged; the dispatcher loop is the same logic, now at app/dispatcher/default.go:417-427.
1. ClientHello split across TLS records (not covered by #7286)
RFC 8446 §5.1 allows a handshake message to be split across several TLS records. SniffTLS parses only the first record (common/protocol/tls/sniff.go:146-152, ReadClientHello(b[5:5+headerLen], h)). If the SNI is in a later record, or the first record holds only part of the ClientHello, sniffing fails even when all the bytes arrived in a single read.
In our tests (dokodemo-door with sniffing.destOverride: ["tls"], routeOnly: true and a domain: ["full:a.test"] rule), all 167 of 167 multi-record ClientHellos were routed by IP instead of by domain. The single-record versions of the same ClientHellos were routed correctly.
2. Single record arriving in 3+ reads (same root cause as #7286)
SniffTLS returns common.ErrNoClue when a record header is present but the record is incomplete (sniff.go:147). The dispatcher stops after two ErrNoClue results (app/dispatcher/default.go:409-419).
#7286 used 100-byte chunks to show this. The relevant real-world case is post-quantum key exchange. ML-KEM-1024 shares, several hybrid key shares, or ML-KEM-768 plus a session ticket push a normal single-record ClientHello past ~2,896 bytes, which is 3+ TCP segments at a 1,448-byte MSS.
Over a 1,500-byte MTU veth link (offloads off), these were our results:
-
Segments 10–30 ms apart: every ClientHello delivered in 3–4 segments lost domain routing (58 of 58). None of the 142 delivered in 1–2 segments did.
-
Segments sent back to back: single-record ClientHellos of 4.2–5.3 KB were sniffed correctly (52 of 52), because they coalesced into fewer reads.
-
Unmodified OpenSSL 3.5.9 client (one write): 2,977 B and 4,648 B ClientHellos were sniffed correctly in 18 of 18 attempts each, even with
netem delay 5ms 2msornetem rate 10mbiton the client's uplink.
So mild jitter and a 10 Mbit/s uplink weren't enough to trigger this. It needs larger gaps between segments, for example from loss and retransmission or sender pacing. I haven't measured real links. Default OpenSSL 3.5 ClientHellos (X25519MLKEM768, ~1.3–1.7 KB) were not affected.
Suggested change (small, keeps the best-effort design)
- In
SniffTLS, returnprotocol.ErrProtoNeedMoreDatainstead ofcommon.ErrNoCluewhen the record header is valid (type 0x16, version 0x03xx, length ≤ 2^14) and the record is just incomplete. The dispatcher's existing 200 ms deadline still bounds the wait. This is the fix proposed in #7286. - Concatenate consecutive handshake records until the ClientHello's 4-byte handshake length is satisfied, bounded by the existing payload buffer (
buf.Size, 8 KiB), before callingReadClientHello.
I'm happy to send a PR with tests for both if that would be welcome.
Reproduction
Two local TLS 1.3 servers: :8500 with only TLS_CHACHA20_POLY1305_SHA256, and :8509 with only TLS_AES_256_GCM_SHA384. The negotiated cipher shows which route was taken.
{
"inbounds": [{"listen": "127.0.0.1", "port": 7023, "protocol": "dokodemo-door",
"settings": {"address": "127.0.0.1", "port": 8509, "network": "tcp"},
"sniffing": {"enabled": true, "destOverride": ["tls"], "routeOnly": true}}],
"outbounds": [{"tag": "ip-default", "protocol": "freedom"},
{"tag": "a-test", "protocol": "freedom", "settings": {"redirect": "127.0.0.1:8500"}}],
"routing": {"rules": [{"type": "field", "domain": ["full:a.test"], "outboundTag": "a-test"}]}
}
python3 split_hello.py 127.0.0.1 7023 a.test # domain route (0x1303)
python3 split_hello.py 127.0.0.1 7023 a.test --records 2 # IP route (0x1302)
python3 split_hello.py 127.0.0.1 7023 a.test --segments 3 --delay 0.02 # IP route (0x1302)
split_hello.py is a small standard-library script that sends one real OpenSSL-generated ClientHello re-framed as requested; I can share it with the maintainers on request. These expected outputs come from our fuzzer runs with the same shapes.
Tested only on our own machines. No third-party servers were involved.
Sathish Kumar P A
- Dominant language
- Go
- Stars
- 43.3k
- Forks
- 6.2k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 55
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from XTLS/Xray-core
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:other issue-rating: 🦞 diamond lobster no-stale P2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
openclaw/crabbox#3249 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
ec2-subnet, security-group and internet-gateway skip all resources when one is deleted during the scanPossibly taken @toabctl claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
gruntwork-io/cloud-nuke#1208 ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
snowflakedb/gosnowflake#1872 ·
-
MCP `shadow` says `out` is a folder, but for TS, Python, C, Go and Ruby it is the module's fileOpengood first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
erkamyaman/rust-anything#1328 ·
Maintainers usually reply within 1 day