mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-10 21:58:52 +00:00
XHTTP & WS & HU & gRPC servers: Require sockopt.trustedXForwardedFor (#6309)
https://github.com/XTLS/Xray-core/pull/6258#issuecomment-4663652131 Behavior: https://github.com/XTLS/Xray-core/pull/6258#issuecomment-4746598275 Replaces https://github.com/XTLS/Xray-core/pull/6159
This commit is contained in:
@@ -19,24 +19,25 @@ import (
|
||||
|
||||
type Listener struct {
|
||||
encoding.UnimplementedGRPCServiceServer
|
||||
ctx context.Context
|
||||
handler internet.ConnHandler
|
||||
local net.Addr
|
||||
config *Config
|
||||
ctx context.Context
|
||||
handler internet.ConnHandler
|
||||
local net.Addr
|
||||
config *Config
|
||||
trustedXForwardedFor []string
|
||||
|
||||
s *grpc.Server
|
||||
}
|
||||
|
||||
func (l Listener) Tun(server encoding.GRPCService_TunServer) error {
|
||||
tunCtx, cancel := context.WithCancel(l.ctx)
|
||||
l.handler(encoding.NewHunkConn(server, cancel))
|
||||
l.handler(encoding.NewHunkConn(server, cancel, l.trustedXForwardedFor))
|
||||
<-tunCtx.Done()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l Listener) TunMulti(server encoding.GRPCService_TunMultiServer) error {
|
||||
tunCtx, cancel := context.WithCancel(l.ctx)
|
||||
l.handler(encoding.NewMultiHunkConn(server, cancel))
|
||||
l.handler(encoding.NewMultiHunkConn(server, cancel, l.trustedXForwardedFor))
|
||||
<-tunCtx.Done()
|
||||
return nil
|
||||
}
|
||||
@@ -74,6 +75,9 @@ func Listen(ctx context.Context, address net.Address, port net.Port, settings *i
|
||||
}
|
||||
|
||||
listener.ctx = ctx
|
||||
if settings.SocketSettings != nil {
|
||||
listener.trustedXForwardedFor = settings.SocketSettings.TrustedXForwardedFor
|
||||
}
|
||||
|
||||
config := tls.ConfigFromStreamSettings(settings)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user