Skip to content

fix(sub): use safe type assertion for xhttp mode field#3990

Open
nnemirovsky wants to merge 1 commit intoMHSanaei:mainfrom
nnemirovsky:fix/xhttp-subscription-panic
Open

fix(sub): use safe type assertion for xhttp mode field#3990
nnemirovsky wants to merge 1 commit intoMHSanaei:mainfrom
nnemirovsky:fix/xhttp-subscription-panic

Conversation

@nnemirovsky
Copy link
Copy Markdown

Summary

Fix HTTP 500 on subscription endpoint for XHTTP/SplitHTTP inbounds.

Unsafe type assertion xhttp["mode"].(string) panics when mode is nil (key absent from stored JSON). This happens when xhttpSettings only contains path without an explicit mode field. The panic is caught by Gin's recovery middleware and returned as HTTP 500 with an empty body. The error is invisible in logs because the subscription server sets gin.DefaultErrorWriter = io.Discard.

Fix

Change all 4 occurrences from unsafe assertion to comma-ok pattern:

// Before (panics on nil)
params["mode"] = xhttp["mode"].(string)

// After (returns "" on nil)
params["mode"], _ = xhttp["mode"].(string)

This matches the fix already applied to gRPC's authority field in commit 21d9881.

Affected functions

  • genVmessLink (line 250)
  • genVlessLink (line 408)
  • genTrojanLink (line 604)
  • genShadowsocksLink (line 803)

Fixes #3987

Unsafe type assertion `xhttp["mode"].(string)` panics when mode is
nil (e.g., when xhttpSettings only contains path without mode). The
panic is caught by Gin's recovery middleware and returned as HTTP 500.

Use comma-ok pattern matching the fix already applied to gRPC's
authority field in 21d9881.

Fixes MHSanaei#3987
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.

Subscription endpoint returns 500 for XHTTP/SplitHTTP inbounds

1 participant