feat(sub): warn when salamander settings cannot reach the client (#6177)

* feat(sub): warn when salamander settings cannot reach the client

A hysteria2 share link carries obfuscation as obfs=salamander plus
obfs-password, and nothing else. Xray's finalmask accepts more than that —
packetSize among them — and those extra settings change what the server expects
on the wire. The emitted URI then looks complete but describes a server the
client cannot reach: every standard client applies plain salamander, the server
drops the packets, and the failure is silent on both ends.

Log the unexpressible keys when building such a link, naming the inbound, so the
cause is visible instead of appearing as a client-side problem.

* fix(sub): deduplicate salamander warnings
This commit is contained in:
n0ctal
2026-08-15 21:15:19 +05:00
committed by GitHub
parent acbf09e710
commit dafd3c0e64
2 changed files with 78 additions and 0 deletions
+23
View File
@@ -9,8 +9,10 @@ import (
"net"
"net/url"
"slices"
"sort"
"strconv"
"strings"
"sync"
"time"
"github.com/gin-gonic/gin"
@@ -26,6 +28,8 @@ import (
"github.com/mhsanaei/3x-ui/v3/internal/xray"
)
var salamanderWarningSeen sync.Map
// SubService provides business logic for generating subscription links and managing subscription data.
type SubService struct {
address string
@@ -1051,6 +1055,12 @@ func (s *SubService) genHysteriaLink(inbound *model.Inbound, email string) strin
}
settings, _ := mask["settings"].(map[string]any)
if pw, ok := settings["password"].(string); ok && pw != "" {
if extra := extraSalamanderKeys(settings); len(extra) > 0 {
warningKey := fmt.Sprintf("%d:%v", inbound.Id, extra)
if _, loaded := salamanderWarningSeen.LoadOrStore(warningKey, struct{}{}); !loaded {
logger.Warningf("SubService - inbound %d: salamander settings %v cannot be expressed in a hysteria2 URI; standard clients will fail the handshake", inbound.Id, extra)
}
}
params["obfs"] = "salamander"
params["obfs-password"] = pw
break
@@ -2696,3 +2706,16 @@ func getHostFromXFH(s string) (string, error) {
}
return s, nil
}
// extraSalamanderKeys lists salamander settings the hysteria2 URI cannot carry.
// A server using them rejects every client built from the emitted link.
func extraSalamanderKeys(settings map[string]any) []string {
var extra []string
for k := range settings {
if k != "password" {
extra = append(extra, k)
}
}
sort.Strings(extra)
return extra
}