fix(sub): use safe type assertion for xhttp mode field#3990
Open
nnemirovsky wants to merge 1 commit intoMHSanaei:mainfrom
Open
fix(sub): use safe type assertion for xhttp mode field#3990nnemirovsky wants to merge 1 commit intoMHSanaei:mainfrom
nnemirovsky wants to merge 1 commit intoMHSanaei:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix HTTP 500 on subscription endpoint for XHTTP/SplitHTTP inbounds.
Unsafe type assertion
xhttp["mode"].(string)panics whenmodeis nil (key absent from stored JSON). This happens whenxhttpSettingsonly containspathwithout an explicitmodefield. 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 setsgin.DefaultErrorWriter = io.Discard.Fix
Change all 4 occurrences from unsafe assertion to comma-ok pattern:
This matches the fix already applied to gRPC's
authorityfield in commit 21d9881.Affected functions
genVmessLink(line 250)genVlessLink(line 408)genTrojanLink(line 604)genShadowsocksLink(line 803)Fixes #3987