mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5944] [Bug]: Host record WebSocket Host header is omitted from Clash/Mihomo subscriptions #4121
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4121
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Concises on GitHub (Jul 13, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5944
Describe the bug
In 3x-ui v3.5.0, a WebSocket Host header configured on the Hosts page is included in the raw/general subscription, but is omitted from the generated Clash/Mihomo subscription when the inbound's own WebSocket
hostfield is empty.This makes
/sub/{subId}and/clash/{subId}semantically inconsistent for the same client and Host record. It also makes the Mihomo nodes unusable behind a CDN or reverse proxy that requires a specific HTTPHostheader: the WebSocket handshake reaches the wrong virtual host and may return HTTP 403.How to reproduce the problem
443, the required SNI, and a Host Header such asorigin.example.com.subId./sub/{subId}. The VLESS URI correctly containshost=origin.example.com./clash/{subId}. The generated proxy hasws-opts.path, butws-opts.headers.Hostis missing.origin.example.cominto the inbound's own WebSocket Host field. The Clash/Mihomo output then contains the expected header.Minimal output comparison:
Expected behavior
For every enabled Host record included in a Clash subscription, its
HostHeaderoverride should be emitted asws-opts.headers.Hostfor WebSocket transports, just as the same override is emitted as thehostquery parameter in the raw/general subscription.The inbound-level WebSocket Host may remain the fallback when a Host record does not define its own Host Header.
Actual behavior
The raw/general subscription honors the Host record's Host Header. The Clash/Mihomo subscription ignores it and only emits a Host header when the same value is duplicated in the inbound's WebSocket transport settings.
Source-level observation
The v3.5.0 source appears to show the format mismatch:
hostToExternalProxyMapstoresHostHeaderashostHeaderininternal/sub/host_sub.go.applyEndpointHostPath.applyHostStreamOverrides, but that function does not projecthostHeaderorpathinto the transport settings.applyTransportininternal/sub/clash_service.goreads the Host value only from the inbound'swsSettings.hostorwsSettings.headers.Relevant source:
Environment
v3.5.026.6.27No real domains, IP addresses, subscription IDs, client UUIDs, or credentials are included in this report.
@github-actions[bot] commented on GitHub (Jul 13, 2026):
Confirmed as a bug. Root cause traced in the current source (HEAD, tagged
v3.5.0, commit4e928a1).Title: Clash/Mihomo (and likely JSON) subscription output does not project a Host record HostHeader/Path override into transport settings
Severity: Medium
Category: Correctness
Why this matters:
hostToExternalProxyMap(internal/sub/host_sub.go:89-94) does store a Host record HostHeader/Path asep["hostHeader"]/ep["path"]. The raw-link path picks these up correctly:applyPathAndHostParams(internal/sub/service.go:1182-1190, invoked fromapplyShareNetworkParamsws case atservice.go:1227-1229) always populatesparams["host"]/params["path"]from the transport settings on the inbound itself first (even to""), so the later call toapplyEndpointHostPath(internal/sub/host_sub.go:258-272) can always overwrite that key with the Host record override. This is why/sub/{subId}is correct.The Clash path never does the equivalent projection.
SubClashService.getProxiescallsapplyHostStreamOverrides(internal/sub/clash_service.go:197, defined atinternal/sub/host_sub.go:127-157), which only handlessockoptParams,finalMask, and (for host endpoints) the Reality SNI override — it never readshostHeader/path. TheapplyTransportws branch (internal/sub/clash_service.go:582-603) then buildsws-optspurely fromstream["wsSettings"], a straight clone of the transport settings on the inbound itself; it never looks atep. When the WebSocket host on the inbound itself is empty,ws-opts.headers.Hostis simply never set, regardless of what the Host record specifies. This matches the lines cited in the report.Two points from tracing the same code paths further, worth confirming before scoping a fix:
applyTransportbuildshttpupgrade-opts(clash_service.go:617-638) andxhttp-opts(viabuildXhttpClashOpts,clash_service.go:428-565, called at639-646) the same way — reading onlystream, neverep. A Host record HostHeader/Path would be dropped for HTTPUpgrade and XHTTP transports too, not just WebSocket.SubJsonService.getConfig(internal/sub/json_service.go:140-242) calls the sameapplyHostStreamOverridesat line 204, with no separate host/path projection anywhere else in that function. The full-config JSON subscription (/json/{subId}) appears to have the identical gap, though this has not been exercised against a live JSON export to confirm.Recommendation: Extend
applyHostStreamOverrides(or add a sibling helper invoked alongside it from bothclash_service.go:197andjson_service.go:204) to projectep["hostHeader"]/ep["path"]into the relevant transport sub-map (wsSettings.host/wsSettings.path,httpupgradeSettings.host/path,xhttpSettings.host/path) beforeapplyTransport/ the JSON outbound builders consumestream, mirroring whatapplyEndpointHostPath/applyPathAndHostParamsalready do on the raw-link path. Keep the value on the inbound itself as fallback when a Host record leaves HostHeader/Path blank, per the expected behavior in the issue.internal/sub/host_sub_test.goandinternal/sub/clash_service_test.goalready have host-record fixtures (wsTLSStream,seedHost) a regression test could extend.Confidence: High for the WebSocket/Clash root cause — verified directly against
internal/sub/clash_service.goandinternal/sub/host_sub.go, matching the citations in the report. Medium for the HTTPUpgrade/XHTTP-within-Clash and JSON-format extensions — traced statically from the same code, not exercised against a running reproduction.@MHSanaei for a decision on scope (WebSocket-only fix vs. all three transports vs. also covering
/json/{subId}).This reply was generated automatically by an AI agent. A maintainer may follow up.
@MHSanaei commented on GitHub (Jul 23, 2026):
Fixed in #6083. Carries a Host record's WebSocket Host header and path into the Clash/Mihomo and JSON subscriptions, not just the raw link.