fix(sub): carry a host's Final Mask into raw share links

A Host's Final Mask was merged into the JSON and Clash subscription
outputs via applyHostStreamOverrides, but the raw link builders compute
the fm param once from the inbound's own streamSettings.finalmask
before the per-host fan-out, and the endpoint override path never read
the host's mask. A Final Mask configured only on a host was silently
dropped from vless/trojan/ss/vmess share links while an inbound-level
mask worked everywhere.

Merge the host mask into the fm param per endpoint with the same
additive semantics as the JSON path (host tcp/udp masks appended to the
inbound's, quicParams only when the inbound has none), for both the
URL-param and the VMess object link forms.

Closes #5831
This commit is contained in:
MHSanaei
2026-07-07 12:44:18 +02:00
parent 52d4af71bc
commit cc3303dd8c
4 changed files with 107 additions and 0 deletions
+38
View File
@@ -305,6 +305,44 @@ func applyEndpointAllowInsecure(e ShareEndpoint, params map[string]string, secur
}
}
// applyEndpointFinalMask merges a host's Final Mask into the raw link's fm
// param, mirroring the applyHostStreamOverrides merge on the JSON/Clash path.
func applyEndpointFinalMask(e ShareEndpoint, params map[string]string) {
if merged, ok := endpointFinalMask(e, params["fm"]); ok {
params["fm"] = merged
}
}
// applyEndpointFinalMaskObj is applyEndpointFinalMask for the VMess object form.
func applyEndpointFinalMaskObj(e ShareEndpoint, obj map[string]any) {
baseFm, _ := obj["fm"].(string)
if merged, ok := endpointFinalMask(e, baseFm); ok {
obj["fm"] = merged
}
}
func endpointFinalMask(e ShareEndpoint, baseFm string) (string, bool) {
if e.ep == nil {
return "", false
}
fm, ok := e.ep["finalMask"].(string)
if !ok || fm == "" {
return "", false
}
var masks map[string]any
if json.Unmarshal([]byte(fm), &masks) != nil || len(masks) == 0 {
return "", false
}
var base any
if baseFm != "" {
var baseMap map[string]any
if json.Unmarshal([]byte(baseFm), &baseMap) == nil {
base = baseMap
}
}
return marshalFinalMask(mergeFinalMask(base, masks))
}
// applyEndpointHostPathObj is applyEndpointHostPath for the VMess object form.
func applyEndpointHostPathObj(e ShareEndpoint, obj map[string]any) {
if e.ep == nil {