[PR #3990] [MERGED] fix(sub): use safe type assertion for xhttp mode field #5576

Closed
opened 2026-10-31 20:47:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/3990
Author: @nnemirovsky
Created: 4/2/2026
Status: ✅ Merged
Merged: 4/19/2026
Merged by: @MHSanaei

Base: main ← Head: fix/xhttp-subscription-panic


📝 Commits (1)

  • b112f4f fix(sub): use safe type assertion for xhttp mode field

📊 Changes

1 file changed (+4 additions, -4 deletions)

View changed files

📝 sub/subService.go (+4 -4)

📄 Description

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 21d98813.

Affected functions

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

Fixes #3987


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/3990 **Author:** [@nnemirovsky](https://github.com/nnemirovsky) **Created:** 4/2/2026 **Status:** ✅ Merged **Merged:** 4/19/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/xhttp-subscription-panic` --- ### 📝 Commits (1) - [`b112f4f`](https://github.com/MHSanaei/3x-ui/commit/b112f4fc984a093bad8da900fc5a6f147eb45228) fix(sub): use safe type assertion for xhttp mode field ### 📊 Changes **1 file changed** (+4 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `sub/subService.go` (+4 -4) </details> ### 📄 Description ## 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: ```go // 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 21d98813. ## Affected functions - `genVmessLink` (line 250) - `genVlessLink` (line 408) - `genTrojanLink` (line 604) - `genShadowsocksLink` (line 803) Fixes #3987 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:47:55 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5576
No description provided.