[GH-ISSUE #5944] [Bug]: Host record WebSocket Host header is omitted from Clash/Mihomo subscriptions #4121

Closed
opened 2026-10-31 20:37:19 +07:00 by bsakaguchi · 2 comments
Owner

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 host field 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 HTTP Host header: the WebSocket handshake reaches the wrong virtual host and may return HTTP 403.

How to reproduce the problem

  1. Create a VLESS + WebSocket + TLS inbound.
  2. Leave the inbound transport's WebSocket Host field empty.
  3. On the Hosts page, add an enabled Host record for that inbound. Configure an alternate address, port 443, the required SNI, and a Host Header such as origin.example.com.
  4. Add a client and retrieve both subscription formats for the same subId.
  5. Decode /sub/{subId}. The VLESS URI correctly contains host=origin.example.com.
  6. Inspect /clash/{subId}. The generated proxy has ws-opts.path, but ws-opts.headers.Host is missing.
  7. As a workaround, put origin.example.com into the inbound's own WebSocket Host field. The Clash/Mihomo output then contains the expected header.

Minimal output comparison:

# Actual /clash/{subId}
network: ws
ws-opts:
  path: /example
# Expected /clash/{subId}
network: ws
ws-opts:
  path: /example
  headers:
    Host: origin.example.com

Expected behavior

For every enabled Host record included in a Clash subscription, its HostHeader override should be emitted as ws-opts.headers.Host for WebSocket transports, just as the same override is emitted as the host query 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:

  • hostToExternalProxyMap stores HostHeader as hostHeader in internal/sub/host_sub.go.
  • The raw-link path applies it through applyEndpointHostPath.
  • The Clash path calls applyHostStreamOverrides, but that function does not project hostHeader or path into the transport settings.
  • applyTransport in internal/sub/clash_service.go reads the Host value only from the inbound's wsSettings.host or wsSettings.headers.

Relevant source:

Environment

  • 3x-ui: v3.5.0
  • Xray-core: 26.6.27
  • Affected area: Subscription generation (Clash/Mihomo)
  • Protocol/transport: VLESS + WebSocket + TLS

No real domains, IP addresses, subscription IDs, client UUIDs, or credentials are included in this report.

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 `host` field 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 HTTP `Host` header: the WebSocket handshake reaches the wrong virtual host and may return HTTP 403. ### How to reproduce the problem 1. Create a VLESS + WebSocket + TLS inbound. 2. Leave the inbound transport's WebSocket **Host** field empty. 3. On the **Hosts** page, add an enabled Host record for that inbound. Configure an alternate address, port `443`, the required SNI, and a **Host Header** such as `origin.example.com`. 4. Add a client and retrieve both subscription formats for the same `subId`. 5. Decode `/sub/{subId}`. The VLESS URI correctly contains `host=origin.example.com`. 6. Inspect `/clash/{subId}`. The generated proxy has `ws-opts.path`, but `ws-opts.headers.Host` is missing. 7. As a workaround, put `origin.example.com` into the inbound's own WebSocket Host field. The Clash/Mihomo output then contains the expected header. Minimal output comparison: ```yaml # Actual /clash/{subId} network: ws ws-opts: path: /example ``` ```yaml # Expected /clash/{subId} network: ws ws-opts: path: /example headers: Host: origin.example.com ``` ### Expected behavior For every enabled Host record included in a Clash subscription, its `HostHeader` override should be emitted as `ws-opts.headers.Host` for WebSocket transports, just as the same override is emitted as the `host` query 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: - `hostToExternalProxyMap` stores `HostHeader` as `hostHeader` in `internal/sub/host_sub.go`. - The raw-link path applies it through `applyEndpointHostPath`. - The Clash path calls `applyHostStreamOverrides`, but that function does not project `hostHeader` or `path` into the transport settings. - `applyTransport` in `internal/sub/clash_service.go` reads the Host value only from the inbound's `wsSettings.host` or `wsSettings.headers`. Relevant source: - https://github.com/MHSanaei/3x-ui/blob/v3.5.0/internal/sub/host_sub.go#L90 - https://github.com/MHSanaei/3x-ui/blob/v3.5.0/internal/sub/host_sub.go#L127 - https://github.com/MHSanaei/3x-ui/blob/v3.5.0/internal/sub/host_sub.go#L258-L267 - https://github.com/MHSanaei/3x-ui/blob/v3.5.0/internal/sub/clash_service.go#L197 - https://github.com/MHSanaei/3x-ui/blob/v3.5.0/internal/sub/clash_service.go#L582-L599 ### Environment - 3x-ui: `v3.5.0` - Xray-core: `26.6.27` - Affected area: Subscription generation (Clash/Mihomo) - Protocol/transport: VLESS + WebSocket + TLS No real domains, IP addresses, subscription IDs, client UUIDs, or credentials are included in this report.
bsakaguchi 2026-10-31 20:37:19 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@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, commit 4e928a1).

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 as ep["hostHeader"]/ep["path"]. The raw-link path picks these up correctly: applyPathAndHostParams (internal/sub/service.go:1182-1190, invoked from applyShareNetworkParams ws case at service.go:1227-1229) always populates params["host"]/params["path"] from the transport settings on the inbound itself first (even to ""), so the later call to applyEndpointHostPath (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.getProxies calls applyHostStreamOverrides (internal/sub/clash_service.go:197, defined at internal/sub/host_sub.go:127-157), which only handles sockoptParams, finalMask, and (for host endpoints) the Reality SNI override — it never reads hostHeader/path. The applyTransport ws branch (internal/sub/clash_service.go:582-603) then builds ws-opts purely from stream["wsSettings"], a straight clone of the transport settings on the inbound itself; it never looks at ep. When the WebSocket host on the inbound itself is empty, ws-opts.headers.Host is 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:

  • applyTransport builds httpupgrade-opts (clash_service.go:617-638) and xhttp-opts (via buildXhttpClashOpts, clash_service.go:428-565, called at 639-646) the same way — reading only stream, never ep. 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 same applyHostStreamOverrides at 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 both clash_service.go:197 and json_service.go:204) to project ep["hostHeader"]/ep["path"] into the relevant transport sub-map (wsSettings.host/wsSettings.path, httpupgradeSettings.host/path, xhttpSettings.host/path) before applyTransport / the JSON outbound builders consume stream, mirroring what applyEndpointHostPath/applyPathAndHostParams already 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.go and internal/sub/clash_service_test.go already 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.go and internal/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.

<!-- gh-comment-id:4961412238 --> @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`, commit `4e928a1`). **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 as `ep["hostHeader"]`/`ep["path"]`. The raw-link path picks these up correctly: `applyPathAndHostParams` (`internal/sub/service.go:1182-1190`, invoked from `applyShareNetworkParams` ws case at `service.go:1227-1229`) always populates `params["host"]`/`params["path"]` from the transport settings on the inbound itself first (even to `""`), so the later call to `applyEndpointHostPath` (`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.getProxies` calls `applyHostStreamOverrides` (`internal/sub/clash_service.go:197`, defined at `internal/sub/host_sub.go:127-157`), which only handles `sockoptParams`, `finalMask`, and (for host endpoints) the Reality SNI override — it never reads `hostHeader`/`path`. The `applyTransport` ws branch (`internal/sub/clash_service.go:582-603`) then builds `ws-opts` purely from `stream["wsSettings"]`, a straight clone of the transport settings on the inbound itself; it never looks at `ep`. When the WebSocket host on the inbound itself is empty, `ws-opts.headers.Host` is 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: - `applyTransport` builds `httpupgrade-opts` (`clash_service.go:617-638`) and `xhttp-opts` (via `buildXhttpClashOpts`, `clash_service.go:428-565`, called at `639-646`) the same way — reading only `stream`, never `ep`. 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 same `applyHostStreamOverrides` at 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 both `clash_service.go:197` and `json_service.go:204`) to project `ep["hostHeader"]`/`ep["path"]` into the relevant transport sub-map (`wsSettings.host`/`wsSettings.path`, `httpupgradeSettings.host`/`path`, `xhttpSettings.host`/`path`) before `applyTransport` / the JSON outbound builders consume `stream`, mirroring what `applyEndpointHostPath`/`applyPathAndHostParams` already 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.go` and `internal/sub/clash_service_test.go` already 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.go` and `internal/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.*
Author
Owner

@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.

<!-- gh-comment-id:5059092508 --> @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.
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#4121
No description provided.