Xray-core icon indicating copy to clipboard operation
Xray-core copied to clipboard

REALITY aborts an authenticated session when dest returns HelloRetryRequest

Open Asmir opened this issue 2 months ago • 2 comments

Integrity requirements

  • [x] I have read all the comments in the issue template and ensured that this issue meet the requirements.
  • [x] 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.
  • [x] I provided the complete config and logs, rather than just providing the truncated parts based on my own judgment.
  • [x] I searched issues and did not find any similar issues.
  • [x] The problem can be successfully reproduced in the latest Release

Description

REALITY authenticates the client, then mirrors the ClientHello to dest. The proxied handshake continues only when that flight is a TLS 1.3 ServerHello whose key_share is X25519 (32 bytes) or X25519MLKEM768. Any other flight is treated as an incorrect ServerHello: handshakeLen[0] stays 0 and, even though hs.c.conn == conn, the server splices a raw pipe to dest and never starts the VLESS session.

consent.yahoo.com:443 answers that mirrored ClientHello with HelloRetryRequest (selected_group secp256r1, 0x0017). The record is 166 bytes.

The check is in github.com/xtls/reality tls.go (commit 9234c772ba8f, the module used by Xray 26.3.27):

if !hs.hello.unmarshal(s2cSaved[recordHeaderLen:handshakeLen]) || hs.hello.vers != VersionTLS12 || hs.hello.supportedVersion != VersionTLS13 || cipherSuiteTLS13ByID(hs.hello.cipherSuite) == nil || (!(hs.hello.serverShare.group == X25519 && len(hs.hello.serverShare.data) == 32) && !(hs.hello.serverShare.group == X25519MLKEM768 && len(hs.hello.serverShare.data) == mlkem.CiphertextSize768+32)) { break f } HelloRetryRequest has no key share of that shape, so this breaks. The fallback is the block commented “if the target sent an incorrect Server Hello”, which raw-forwards to dest. The error path then is target sent incorrect server hello or handshake incomplete.

Recognizing the HRR random is not enough for this dest. After the retry, Yahoo’s ServerHello uses secp256r1, which fails the same allow-list. A fix needs to mirror HRR and the second ClientHello (the REALITY session id must stay the authenticator) and accept the ServerHello that follows, including secp256r1.

Reproduction Method

  1. Start the server and client configs below with Xray 26.3.27. realitySettings.show is true, log level is debug, dnsLog is true.
  2. curl -x socks5h://127.0.0.1:1080 consent.yahoo.com
  3. The server log shows hs.c.conn == conn: true and Server Hello: 166, then the connection is not proxied.

Client config


{
  "log": { "loglevel": "debug", "dnsLog": true },
  "inbounds": [{
    "listen": "127.0.0.1",
    "port": 1080,
    "protocol": "socks",
    "settings": { "udp": false }
  }],
  "outbounds": [{
    "protocol": "vless",
    "settings": {
      "vnext": [{
        "address": "127.0.0.1",
        "port": 443,
        "users": [{
          "id": "6c1e0b4a-9f27-4d5e-8a13-2b7c9d0e4f61",
          "encryption": "none",
          "flow": "xtls-rprx-vision"
        }]
      }]
    },
    "streamSettings": {
      "network": "tcp",
      "security": "reality",
      "realitySettings": {
        "show": true,
        "fingerprint": "chrome",
        "serverName": "consent.yahoo.com",
        "publicKey": "b12PulcAi-gb9Nms8O42ewxEnDtsxKiMKGmZdHkqKV4",
        "shortId": "c3a91f07e25b4d86"
      }
    }
  }]
}

Server config


{
  "log": { "loglevel": "debug", "dnsLog": true },
  "inbounds": [{
    "listen": "127.0.0.1",
    "port": 443,
    "protocol": "vless",
    "settings": {
      "clients": [{
        "id": "6c1e0b4a-9f27-4d5e-8a13-2b7c9d0e4f61",
        "flow": "xtls-rprx-vision"
      }],
      "decryption": "none"
    },
    "streamSettings": {
      "network": "tcp",
      "security": "reality",
      "realitySettings": {
        "show": true,
        "dest": "consent.yahoo.com:443",
        "serverNames": ["consent.yahoo.com"],
        "privateKey": "SOir5guA9kxxeBdtlAiMscseM9m-GEnz1QrexDnneUs",
        "shortIds": ["c3a91f07e25b4d86"]
      }
    }
  }],
  "outbounds": [{ "protocol": "freedom" }]
}

Client log


Xray 26.3.27 (Xray, Penetrates Everything.) d2758a0 (go1.26.1 darwin/arm64)
A unified platform for anti-censorship.
2026/09/28 09:58:24.037671 [Info] infra/conf/serial: Reading config: &{Name:/tmp/xray_hrr/client.json Format:json}
2026/09/28 09:58:24.040302 [Debug] app/log: Logger started
2026/09/28 09:58:24.040718 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:1080
2026/09/28 09:58:24.040726 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:1081
2026/09/28 09:58:24.041567 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:1080
2026/09/28 09:58:24.041589 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:1081
2026/09/28 09:58:24.042054 [Warning] core: Xray 26.3.27 started
2026/09/28 09:58:24.193718 [Info] [1464981268] proxy/socks: TCP Connect request to tcp:www.example.com:443
2026/09/28 09:58:24.193751 [Info] [1464981268] app/dispatcher: taking detour [out-google] for [tcp:www.example.com:443]
2026/09/28 09:58:24.193750 from tcp:127.0.0.1:60050 accepted tcp:www.example.com:443 [socks-google -> out-google]
2026/09/28 09:58:24.194286 [Info] [1464981268] transport/internet/tcp: dialing TCP to tcp:127.0.0.1:8444
2026/09/28 09:58:24.194505 [Debug] [1464981268] transport/internet: dialing to tcp:127.0.0.1:8444
2026/09/28 09:58:24.275916 [Info] [1464981268] proxy/vless/outbound: tunneling request to tcp:www.example.com:443 via 127.0.0.1:8444
2026/09/28 09:58:24.276292 [Debug] [1464981268] proxy: XtlsFilterTls found tls client hello! 325
2026/09/28 09:58:24.276305 [Debug] [1464981268] proxy: XtlsPadding 325 996 0
2026/09/28 09:58:29.390877 [Debug] [1464981268] proxy: Xtls Unpadding new block, content 1440 padding 255 command 0
2026/09/28 09:58:29.390896 [Debug] [1464981268] proxy: XtlsFilterTls found tls 1.3! 1163 TLS_CHACHA20_POLY1305_SHA256
2026/09/28 09:58:29.393636 [Debug] [1464981268] proxy: Xtls Unpadding new block, content 2534 padding 6 command 0
2026/09/28 09:58:29.397693 [Debug] [1464981268] proxy: XtlsPadding 64 1054 0
2026/09/28 09:58:29.398013 [Debug] [1464981268] proxy: XtlsPadding 86 1028 2
2026/09/28 09:58:29.421674 [Debug] [1464981268] proxy: Xtls Unpadding new block, content 71 padding 962 command 2
2026/09/28 09:58:29.421693 [Debug] [1464981268] proxy: CopyRawConn (maybe) readv
2026/09/28 09:58:29.465066 [Info] [1582724813] proxy/socks: TCP Connect request to tcp:www.example.com:443
2026/09/28 09:58:29.465100 [Info] [1582724813] app/dispatcher: taking detour [out-yahoo] for [tcp:www.example.com:443]
2026/09/28 09:58:29.465117 [Info] [1582724813] transport/internet/tcp: dialing TCP to tcp:127.0.0.1:8443
2026/09/28 09:58:29.465172 [Debug] [1582724813] transport/internet: dialing to tcp:127.0.0.1:8443
2026/09/28 09:58:29.465080 from tcp:127.0.0.1:60066 accepted tcp:www.example.com:443 [socks-yahoo -> out-yahoo]
2026/09/28 09:58:29.670550 [Error] [1582724813] transport/internet/reality: REALITY: received real certificate (potential MITM or redirection)
2026/09/28 09:58:29.670632 [Info] [1582724813] transport/internet/tcp: dialing TCP to tcp:127.0.0.1:8443
2026/09/28 09:58:29.670649 [Debug] [1582724813] transport/internet: dialing to tcp:127.0.0.1:8443
2026/09/28 09:58:29.889725 [Error] [1582724813] transport/internet/reality: REALITY: received real certificate (potential MITM or redirection)
2026/09/28 09:58:30.090890 [Info] [1582724813] transport/internet/tcp: dialing TCP to tcp:127.0.0.1:8443
2026/09/28 09:58:30.091024 [Debug] [1582724813] transport/internet: dialing to tcp:127.0.0.1:8443
2026/09/28 09:58:30.292690 [Error] [1582724813] transport/internet/reality: REALITY: received real certificate (potential MITM or redirection)
2026/09/28 09:58:30.693812 [Info] [1582724813] transport/internet/tcp: dialing TCP to tcp:127.0.0.1:8443
2026/09/28 09:58:30.693838 [Debug] [1582724813] transport/internet: dialing to tcp:127.0.0.1:8443
2026/09/28 09:58:30.897984 [Error] [1582724813] transport/internet/reality: REALITY: received real certificate (potential MITM or redirection)
2026/09/28 09:58:31.499542 [Info] [1582724813] transport/internet/tcp: dialing TCP to tcp:127.0.0.1:8443
2026/09/28 09:58:31.499676 [Debug] [1582724813] transport/internet: dialing to tcp:127.0.0.1:8443
2026/09/28 09:58:31.697968 [Error] [1582724813] transport/internet/reality: REALITY: received real certificate (potential MITM or redirection)
2026/09/28 09:58:32.500630 [Info] [1582724813] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/vless/outbound: failed to find an available destination > common/retry: [transport/internet/reality: REALITY: processed invalid connection] > common/retry: all retry attempts failed
2026/09/28 09:58:33.153071 [Debug] app/log: Logger closing

Server log


Xray 26.3.27 (Xray, Penetrates Everything.) d2758a0 (go1.26.1 darwin/arm64)
A unified platform for anti-censorship.
2026/09/28 09:58:24.037671 [Info] infra/conf/serial: Reading config: &{Name:/tmp/xray_hrr/server.json Format:json}
2026/09/28 09:58:24.039907 [Warning] infra/conf: REALITY: Listening on non-443 ports may get your IP blocked by the GFW
2026/09/28 09:58:24.040066 [Warning] infra/conf: REALITY: Listening on non-443 ports may get your IP blocked by the GFW
2026/09/28 09:58:24.040301 [Debug] app/log: Logger started
2026/09/28 09:58:24.040719 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:8443
2026/09/28 09:58:24.040726 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:8444
2026/09/28 09:58:24.041568 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:8443
2026/09/28 09:58:24.041615 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:8444
2026/09/28 09:58:24.043198 [Warning] core: Xray 26.3.27 started
REALITY remoteAddr: 127.0.0.1:60051
REALITY remoteAddr: 127.0.0.1:60051	hs.c.AuthKey[:16]: [81 245 163 195 66 142 176 199 50 221 58 113 148 124 35 222]	AEAD: *gcm.GCM
REALITY remoteAddr: 127.0.0.1:60051	hs.c.ClientVer: [26 3 27]
REALITY remoteAddr: 127.0.0.1:60051	hs.c.ClientTime: 2026-09-28 09:58:24 +0200 CEST
REALITY remoteAddr: 127.0.0.1:60051	hs.c.ClientShortId: [1 35 69 103 137 171 205 239]
REALITY remoteAddr: 127.0.0.1:60051	hs.c.conn == conn: true
REALITY remoteAddr: 127.0.0.1:60051	len(s2cSaved): 1400	Server Hello: 1215
REALITY remoteAddr: 127.0.0.1:60051	len(s2cSaved): 185	Change Cipher Spec: 6
REALITY remoteAddr: 127.0.0.1:60051	len(s2cSaved): 179	Encrypted Extensions: 4522
REALITY remoteAddr: 127.0.0.1:60051	is using X25519MLKEM768 for TLS' communication: true
REALITY remoteAddr: 127.0.0.1:60051	is using ML-DSA-65 for cert's extra signature: false
REALITY remoteAddr: 127.0.0.1:60051	hs.handshake() err: 
REALITY remoteAddr: 127.0.0.1:60051	hs.readClientFinished() err: 
REALITY remoteAddr: 127.0.0.1:60051	len(postHandshakeRecord): 962
REALITY remoteAddr: 127.0.0.1:60051	len(postHandshakeRecord): 62
REALITY remoteAddr: 127.0.0.1:60051	hs.c.isHandshakeComplete.Load(): true
2026/09/28 09:58:29.278768 [Info] [2453057225] proxy/vless/inbound: firstLen = 1186
2026/09/28 09:58:29.278906 [Info] [2453057225] proxy/vless/inbound: received request for tcp:www.example.com:443
2026/09/28 09:58:29.278936 [Info] [2453057225] app/dispatcher: default route for tcp:www.example.com:443
2026/09/28 09:58:29.279088 from 127.0.0.1:60051 accepted tcp:www.example.com:443
2026/09/28 09:58:29.279123 [Info] [2453057225] transport/internet/tcp: dialing TCP to tcp:www.example.com:443
2026/09/28 09:58:29.279139 [Debug] [2453057225] transport/internet: dialing to tcp:www.example.com:443
2026/09/28 09:58:29.361334 [Info] [2453057225] proxy/freedom: connection opened to tcp:www.example.com:443, local endpoint :60063, remote endpoint 172.66.147.243:443
2026/09/28 09:58:29.361395 [Debug] [2453057225] proxy: CopyRawConn (maybe) readv
2026/09/28 09:58:29.361410 [Debug] [2453057225] proxy: Xtls Unpadding new block, content 325 padding 996 command 0
2026/09/28 09:58:29.361425 [Debug] [2453057225] proxy: XtlsFilterTls found tls client hello! 325
2026/09/28 09:58:29.389694 [Debug] [2453057225] proxy: XtlsFilterTls found tls 1.3! 1440 TLS_CHACHA20_POLY1305_SHA256
2026/09/28 09:58:29.389731 [Debug] [2453057225] proxy: XtlsPadding 1440 255 0
2026/09/28 09:58:29.393557 [Debug] [2453057225] proxy: XtlsPadding 2534 6 0
2026/09/28 09:58:29.397775 [Debug] [2453057225] proxy: Xtls Unpadding new block, content 64 padding 1054 command 0
2026/09/28 09:58:29.398099 [Debug] [2453057225] proxy: Xtls Unpadding new block, content 86 padding 1028 command 2
2026/09/28 09:58:29.421559 [Debug] [2453057225] proxy: XtlsPadding 71 962 2
REALITY remoteAddr: 127.0.0.1:60067
REALITY remoteAddr: 127.0.0.1:60067	hs.c.AuthKey[:16]: [86 68 243 15 128 103 37 65 108 36 80 110 49 54 9 31]	AEAD: *gcm.GCM
REALITY remoteAddr: 127.0.0.1:60067	hs.c.ClientVer: [26 3 27]
REALITY remoteAddr: 127.0.0.1:60067	hs.c.ClientTime: 2026-09-28 09:58:29 +0200 CEST
REALITY remoteAddr: 127.0.0.1:60067	hs.c.ClientShortId: [1 35 69 103 137 171 205 239]
REALITY remoteAddr: 127.0.0.1:60067	hs.c.conn == conn: true
REALITY remoteAddr: 127.0.0.1:60067	len(s2cSaved): 166	Server Hello: 166
REALITY remoteAddr: 127.0.0.1:60069
REALITY remoteAddr: 127.0.0.1:60067	hs.c.isHandshakeComplete.Load(): false
2026/09/28 09:58:29.729795 [Info] transport/internet/tcp: REALITY: processed invalid connection from 127.0.0.1:60067: target sent incorrect server hello or handshake incomplete
REALITY remoteAddr: 127.0.0.1:60069	hs.c.AuthKey[:16]: [234 224 235 174 200 96 197 242 111 48 11 38 202 160 90 36]	AEAD: *gcm.GCM
REALITY remoteAddr: 127.0.0.1:60069	hs.c.ClientVer: [26 3 27]
REALITY remoteAddr: 127.0.0.1:60069	hs.c.ClientTime: 2026-09-28 09:58:29 +0200 CEST
REALITY remoteAddr: 127.0.0.1:60069	hs.c.ClientShortId: [1 35 69 103 137 171 205 239]
REALITY remoteAddr: 127.0.0.1:60069	hs.c.conn == conn: true
REALITY remoteAddr: 127.0.0.1:60069	len(s2cSaved): 166	Server Hello: 166
REALITY remoteAddr: 127.0.0.1:60069	hs.c.isHandshakeComplete.Load(): false
2026/09/28 09:58:29.955489 [Info] transport/internet/tcp: REALITY: processed invalid connection from 127.0.0.1:60069: target sent incorrect server hello or handshake incomplete
REALITY remoteAddr: 127.0.0.1:60071
REALITY remoteAddr: 127.0.0.1:60071	hs.c.AuthKey[:16]: [174 35 128 113 61 238 66 17 237 74 89 45 176 224 27 179]	AEAD: *gcm.GCM
REALITY remoteAddr: 127.0.0.1:60071	hs.c.ClientVer: [26 3 27]
REALITY remoteAddr: 127.0.0.1:60071	hs.c.ClientTime: 2026-09-28 09:58:30 +0200 CEST
REALITY remoteAddr: 127.0.0.1:60071	hs.c.ClientShortId: [1 35 69 103 137 171 205 239]
REALITY remoteAddr: 127.0.0.1:60071	hs.c.conn == conn: true
REALITY remoteAddr: 127.0.0.1:60071	len(s2cSaved): 166	Server Hello: 166
REALITY remoteAddr: 127.0.0.1:60071	hs.c.isHandshakeComplete.Load(): false
2026/09/28 09:58:30.353256 [Info] transport/internet/tcp: REALITY: processed invalid connection from 127.0.0.1:60071: target sent incorrect server hello or handshake incomplete
REALITY remoteAddr: 127.0.0.1:60075
REALITY remoteAddr: 127.0.0.1:60075	hs.c.AuthKey[:16]: [244 199 55 150 165 20 156 175 66 125 129 193 89 4 175 230]	AEAD: *gcm.GCM
REALITY remoteAddr: 127.0.0.1:60075	hs.c.ClientVer: [26 3 27]
REALITY remoteAddr: 127.0.0.1:60075	hs.c.ClientTime: 2026-09-28 09:58:30 +0200 CEST
REALITY remoteAddr: 127.0.0.1:60075	hs.c.ClientShortId: [1 35 69 103 137 171 205 239]
REALITY remoteAddr: 127.0.0.1:60075	hs.c.conn == conn: true
REALITY remoteAddr: 127.0.0.1:60075	len(s2cSaved): 166	Server Hello: 166
REALITY remoteAddr: 127.0.0.1:60075	hs.c.isHandshakeComplete.Load(): false
2026/09/28 09:58:30.959794 [Info] transport/internet/tcp: REALITY: processed invalid connection from 127.0.0.1:60075: target sent incorrect server hello or handshake incomplete
REALITY remoteAddr: 127.0.0.1:60077
REALITY remoteAddr: 127.0.0.1:60077	hs.c.AuthKey[:16]: [103 176 250 238 233 120 163 123 63 33 174 127 10 58 69 114]	AEAD: *gcm.GCM
REALITY remoteAddr: 127.0.0.1:60077	hs.c.ClientVer: [26 3 27]
REALITY remoteAddr: 127.0.0.1:60077	hs.c.ClientTime: 2026-09-28 09:58:31 +0200 CEST
REALITY remoteAddr: 127.0.0.1:60077	hs.c.ClientShortId: [1 35 69 103 137 171 205 239]
REALITY remoteAddr: 127.0.0.1:60077	hs.c.conn == conn: true
REALITY remoteAddr: 127.0.0.1:60077	len(s2cSaved): 166	Server Hello: 166
REALITY remoteAddr: 127.0.0.1:60077	hs.c.isHandshakeComplete.Load(): false
2026/09/28 09:58:31.758641 [Info] transport/internet/tcp: REALITY: processed invalid connection from 127.0.0.1:60077: target sent incorrect server hello or handshake incomplete
2026/09/28 09:58:33.153073 [Debug] app/log: Logger closing

Asmir avatar Sep 28 '26 15:09 Asmir

I reproduced this locally and can confirm the behavior, but I believe it is the expected outcome of an unsupported target rather than a defect in REALITY. Evidence below.

1. The target does not support X25519, for any client. Probing consent.yahoo.com:443 directly with a plain Go crypto/tls client (no REALITY involved):

Groups offered by the client Server's first handshake message
X25519MLKEM768 + X25519 key shares (Go default) HelloRetryRequest, 166 bytes, selected_group = secp256r1
X25519 only fatal alert unexpected_message
P-384 only ServerHello with a P-384 key share

All six IPv4 addresses it resolves to behave the same. xray tls ping consent.yahoo.com reports TLS Post-Quantum key exchange: false (CurveP256), and curl --tlsv1.3 --curves X25519 fails the handshake. So the HRR is the server's configuration and is not specific to REALITY. Other Yahoo hosts such as www.yahoo.com negotiate X25519MLKEM768 directly and work fine as a target.

2. It also misses the documented minimum for a target. The REALITY README asks for "TLSv1.3 and H2". This host does not negotiate h2: offering h2,http/1.1 gets no ALPN back, and curl --http2 ends up on HTTP/1.1.

3. The X25519 requirement has been stated before. #1857 (2023) is the same mechanism with a P-384 target. RPRX answered that the target did not select X25519 for Chrome's Client Hello and "不符合条件, 因为 REALITY 需要 X25519" (it does not qualify, because REALITY needs X25519), and that the server makes Chrome redo the handshake. The Server Hello: 93 in that log matches the size of a HelloRetryRequest without a cookie, given the 32-byte session ID a REALITY client always sends (5 + 4 + 2 + 32 + 33 + 2 + 1 + 2 + 6 + 6), while any TLS 1.3 ServerHello carrying a key share is at least 127 bytes under the same condition. The 166 here is that plus a 73-byte cookie extension. That issue was closed as not planned.

4. The code path is deliberate, not a regression. The X25519 check on the target's ServerHello has been there since REALITY's handshake logic first landed (XTLS/REALITY@5e6719e, Feb 2023) and was later extended to X25519MLKEM768. The fallback you hit is written specifically for the authenticated case: if hs.c.conn == conn { // if we processed the Client Hello successfully but the target did not (XTLS/REALITY@e426190). The check also guards the handshake code behind it: handshake_server_tls13.go copies the target's ServerHello and generates its own key share with a hard-coded generateECDHEKey(..., X25519). Relaxing the check alone would not make a P-256 target work.

Why supporting it would be a feature rather than a fix. When the target sends a HelloRetryRequest, REALITY cannot answer with its own X25519 ServerHello instead: replaying the same Client Hello to the target would then give a different response, which is exactly the distinguishability REALITY is meant to avoid. Supporting such targets needs HRR and second-Client-Hello mirroring, as you outlined, plus non-X25519 key exchange in REALITY's own handshake. That may be worth a feature request, but falling back to the target when it cannot be mirrored is the intended, safe behavior.

The practical fix is to pick a target that negotiates X25519 or X25519MLKEM768 directly. xray tls ping <domain> shows it in the TLS Post-Quantum key exchange line: true or false (X25519) is fine. What I agree is missing is documentation: neither the README nor the Xray docs state the X25519 requirement explicitly.

Tested with the official Xray 26.3.27 and 26.9.9 Windows builds, using your configs with only the ports changed: with consent.yahoo.com as the target both versions fail, and with www.yahoo.com as the control both succeed.


AI assistance: this investigation and write-up were done with Claude (Opus 5.5). Every number above is measured on the reporting host, not estimated.

yx64 avatar Sep 29 '26 02:09 yx64

reality的密钥协商隐秘存在于client/server hello的x25519密钥中 如果伪装网站不使用x25519它那么本来就用不了

Fangliding avatar Sep 30 '26 13:09 Fangliding