From 4976085ddb8a034de61be133f5316aab14eab8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Thu, 28 Aug 2025 21:41:44 +0800 Subject: [PATCH] Socks/HTTP inbound: Fix unexpected rawConn copy (#5041) Fixes https://github.com/XTLS/Xray-core/issues/5040 --- proxy/http/server.go | 8 +++++++- proxy/socks/server.go | 12 ++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/proxy/http/server.go b/proxy/http/server.go index 3721dd47..8d6290a3 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -23,6 +23,7 @@ import ( "github.com/xtls/xray-core/core" "github.com/xtls/xray-core/features/policy" "github.com/xtls/xray-core/features/routing" + "github.com/xtls/xray-core/proxy" "github.com/xtls/xray-core/transport/internet/stat" ) @@ -95,6 +96,9 @@ func (s *Server) ProcessWithFirstbyte(ctx context.Context, network net.Network, inbound.User = &protocol.MemoryUser{ Level: s.config.UserLevel, } + if !proxy.IsRAWTransport(conn) { + inbound.CanSpliceCopy = 3 + } var reader *bufio.Reader if len(firstbyte) > 0 { readerWithoutFirstbyte := bufio.NewReaderSize(readerOnly{conn}, buf.Size) @@ -207,7 +211,9 @@ func (s *Server) handleConnect(ctx context.Context, _ *http.Request, reader *buf } responseDone := func() error { - inbound.CanSpliceCopy = 1 + if inbound.CanSpliceCopy == 2 { + inbound.CanSpliceCopy = 1 + } defer timer.SetTimeout(plcy.Timeouts.UplinkOnly) v2writer := buf.NewWriter(conn) diff --git a/proxy/socks/server.go b/proxy/socks/server.go index 8a159fad..08e2e657 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -19,6 +19,7 @@ import ( "github.com/xtls/xray-core/core" "github.com/xtls/xray-core/features/policy" "github.com/xtls/xray-core/features/routing" + "github.com/xtls/xray-core/proxy" "github.com/xtls/xray-core/proxy/http" "github.com/xtls/xray-core/transport/internet/stat" "github.com/xtls/xray-core/transport/internet/udp" @@ -75,6 +76,9 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con inbound.User = &protocol.MemoryUser{ Level: s.config.UserLevel, } + if !proxy.IsRAWTransport(conn) { + inbound.CanSpliceCopy = 3 + } switch network { case net.Network_TCP: @@ -199,7 +203,9 @@ func (s *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ } responseDone := func() error { - inbound.CanSpliceCopy = 1 + if inbound.CanSpliceCopy == 2 { + inbound.CanSpliceCopy = 1 + } defer timer.SetTimeout(plcy.Timeouts.UplinkOnly) v2writer := buf.NewWriter(writer) @@ -259,7 +265,9 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis if inbound != nil && inbound.Source.IsValid() { errors.LogInfo(ctx, "client UDP connection from ", inbound.Source) } - inbound.CanSpliceCopy = 1 + if inbound.CanSpliceCopy == 2 { + inbound.CanSpliceCopy = 1 + } var dest *net.Destination