Skip to content

XTLS Vision: Do not send outer close_notify after switching to direct copy - #6816

Closed
4RH1T3CT0R7 wants to merge 1 commit into
XTLS:mainfrom
4RH1T3CT0R7:fix/vision-no-outer-close-notify
Closed

4RH1T3CT0R7 wants to merge 1 commit into
XTLS:mainfrom
4RH1T3CT0R7:fix/vision-no-outer-close-notify

Conversation

@4RH1T3CT0R7

@4RH1T3CT0R7 4RH1T3CT0R7 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

After a Vision writer sends CommandPaddingDirect, the peer reads the raw socket. At teardown the outer TLS/REALITY conn is still closed as usual, and its Close() writes an encrypted close_notify onto that same socket. The peer can't tell those 24 bytes apart from relayed data, so it forwards them to the inner TLS endpoint, which fails with bad record MAC. This shows up when the origin closes without its own close_notify, or when the client keeps reading to EOF.

The fix: the writer records that it sent CommandPaddingDirect (UplinkWriterDirectCopySent / DownlinkWriterDirectCopySent). When VLESS inbound/outbound Process returns, if that flag is set, it closes the conn returned by UnwrapRawConn first. The later outer Close() then fails to write its alert instead of sending it to the peer. When no switch happened, close works as before. With VLESS encryption, UnwrapRawConn stops at the TLS layer, so that close_notify still goes out correctly.

TestVlessXtlsVisionDirectCopyClose uses a TLS 1.3 destination that closes without close_notify, in both directions. On main it fails every run with bad record MAC (Windows and Linux), and it passes with this change. Reverting either the inbound or the outbound half makes the matching direction fail again. I also ran go test ./proxy/... and the VLESS scenario tests, plus a race-built run under Linux: no new races, only the existing NumberOfPacketToFilter/cert ones.

This probably also explains some of the reports in #4878.

… copy

Once a Vision writer sends CommandPaddingDirect, the peer reads the raw
socket, but the outer TLS/REALITY conn is still closed normally at the end
and its Close() writes an encrypted close_notify onto that socket. The peer
forwards those bytes to the inner TLS endpoint, which fails with "bad record
MAC". Remember that the command was sent and close the raw conn first, so
the outer alert write fails instead of reaching the peer.

Fixes XTLS#6794
@Fangliding

Copy link
Copy Markdown
Member

这样没法抑制来自其他组件稀奇古怪的close调用 我想到了一个更好的办法

@Fangliding Fangliding closed this Sep 25, 2026
GFW-knocker pushed a commit to GFW-knocker/Xray-core that referenced this pull request Oct 2, 2026
XTLS#6834)

XTLS#6816 (comment)
XTLS#6794 (comment)
XTLS#6834 (comment)

Fixes XTLS#6794 (comment)
Fixes XTLS#6124 (comment)
Fixes XTLS#4878 (comment)

---------

Co-authored-by: Artem Lytkin <[email protected]>
(cherry picked from commit e5e85ca)

[GFW-knocker: hand-merged import block in tls/tls.go (the fork no longer
imports slices there); code applied unchanged. Covers vless and mvless, which
share proxy.VisionReader/VisionWriter.]
onesyue pushed a commit to onesyue/Xray-core that referenced this pull request Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants