From f754246e3e8f021aae2a7ad1b18729dafe8d0e9d Mon Sep 17 00:00:00 2001 From: Mohamadhosein Moazennia Date: Wed, 18 Feb 2026 20:11:42 +0330 Subject: [PATCH] fix: add nil checks in xray API to prevent panics --- xray/api.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xray/api.go b/xray/api.go index 2312d2e4..1b04bf47 100644 --- a/xray/api.go +++ b/xray/api.go @@ -72,6 +72,9 @@ func (x *XrayAPI) Close() { // AddInbound adds a new inbound configuration to the Xray core via gRPC. func (x *XrayAPI) AddInbound(inbound []byte) error { + if x.HandlerServiceClient == nil { + return common.NewError("xray handler service client is not initialized") + } client := *x.HandlerServiceClient conf := new(conf.InboundDetourConfig) @@ -94,6 +97,9 @@ func (x *XrayAPI) AddInbound(inbound []byte) error { // DelInbound removes an inbound configuration from the Xray core by tag. func (x *XrayAPI) DelInbound(tag string) error { + if x.HandlerServiceClient == nil { + return common.NewError("xray handler service client is not initialized") + } client := *x.HandlerServiceClient _, err := client.RemoveInbound(context.Background(), &command.RemoveInboundRequest{ Tag: tag, @@ -103,6 +109,9 @@ func (x *XrayAPI) DelInbound(tag string) error { // AddUser adds a user to an inbound in the Xray core using the specified protocol and user data. func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]any) error { + if x.HandlerServiceClient == nil { + return common.NewError("xray handler service client is not initialized") + } var account *serial.TypedMessage switch Protocol { case "vmess": @@ -187,6 +196,9 @@ func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]an // RemoveUser removes a user from an inbound in the Xray core by email. func (x *XrayAPI) RemoveUser(inboundTag, email string) error { + if x.HandlerServiceClient == nil { + return common.NewError("xray handler service client is not initialized") + } ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel()