TLS sniffer does not read SNI from a ClientHello split across TLS records (and large post-quantum ClientHellos make #7286's case more common)

Abierto
#7,540 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Fangliding ya está trabajando en esto.

Desde el 1/12/2026.

  • #7542 de @amstedy — cerrado sin fusionar
  • #7544 de @Fangliding — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
57/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
networking

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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 2ms or netem rate 10mbit on 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)
  1. In SniffTLS, return protocol.ErrProtoNeedMoreData instead of common.ErrNoClue when 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.
  2. 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 calling ReadClientHello.

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

Lenguaje dominante
Go
Estrellas
43.3k
Forks
6.2k
Merge medio
2 d 11 h
PR fusionados (30 d)
55

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de XTLS/Xray-core

Todos los issues de XTLS/Xray-core

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.