[PR #4073] [MERGED] Fix Hysteria External Proxy + include Hysteria in Clash subscription (#4053) #5590

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4073
Author: @pwnnex
Created: 4/21/2026
Status: ✅ Merged
Merged: 4/22/2026
Merged by: @MHSanaei

Base: main ← Head: fix/hysteria-external-proxy-and-clash


📝 Commits (3)

  • 3213d62 Fix Hysteria External Proxy + include Hysteria in Clash subscription (#4053)
  • e20a8c7 gofmt: align map keys in buildHysteriaProxy
  • 863f767 Merge branch 'main' into fix/hysteria-external-proxy-and-clash

📊 Changes

2 files changed (+135 additions, -3 deletions)

View changed files

📝 sub/subClashService.go (+86 -0)
📝 sub/subService.go (+49 -3)

📄 Description

Closes #4053.

Two related gaps on the Hysteria side of the subscription layer.

sub/subService.go → genHysteriaLink built its link as

link := fmt.Sprintf("%s://%s@%s:%d", protocol, auth, s.address, inbound.Port)

with no reference to the inbound's externalProxy array. Every other generator (genVmessLink, genVlessLink, genTrojanLink, genShadowsocksLink) iterates that array and emits one link per entry, substituting dest / port / remark. Hysteria was the outlier, so admins who pointed a Hysteria inbound at an alternate endpoint (typical scenario: a CDN hostname that forwards UDP to the node) still got a subscription with the original server address. The issue reporter ran into exactly this.

Fix: mirror the pattern. When externalProxy is non-empty, fan out — one link per entry — substituting dest / port and using the entry's remark as a suffix. If the array is absent or empty, keep the previous behaviour (use the request host + inbound.Port).

While I was in there, I also propagated the salamander obfs password (finalmask.udp[salamander].settings.password) as obfs=salamander&obfs-password=…. The panel-side link generator (web/assets/js/model/inbound.js → genHysteriaLink) already emits these query params, so the subscription output was just lagging.

2. Hysteria missing from Clash subscription

sub/subClashService.go → buildProxy had a protocol switch with cases for VMESS / VLESS / Trojan / Shadowsocks and a default: return nil. Hysteria inbounds fell into the default branch and silently vanished from the YAML — the user saw every other protocol in their Clash config except the Hysteria ones.

Fix: route Hysteria through a dedicated buildHysteriaProxy helper before the existing applyTransport / applySecurity helpers run. Those helpers model xray streamSettings.network / streamSettings.security, which Hysteria doesn't use — Hysteria carries its own UDP transport and TLS handshake. The helper reads inbound.StreamSettings directly instead of going through streamData / tlsData, because those prune fields (allowInsecure, the salamander finalmask.udp block) that the mihomo Hysteria proxy needs preserved.

Output shape matches mihomo's docs:

- name: <remark>
  type: hysteria2              # or "hysteria" for v1 inbounds
  server: <ext-proxy-host or inbound.Listen>
  port: <ext-proxy-port or inbound.Port>
  password: <client.Auth>      # "auth-str" for v1
  udp: true
  sni: <tlsSettings.serverName>
  alpn: [h3]                   # whatever tlsSettings.alpn has
  skip-cert-verify: true       # iff tlsSettings.settings.allowInsecure
  client-fingerprint: chrome   # iff tlsSettings.settings.fingerprint set
  obfs: salamander
  obfs-password: <finalmask.udp[salamander].settings.password>

The existing getProxies fanout over externalProxy is untouched and plugs in automatically, so once Hysteria is recognised by buildProxy it also picks up External Proxy entries in the Clash output.

Diff size

sub/subService.go: genHysteriaLink rewritten (+49 −3)
sub/subClashService.go: +86 (early Hysteria dispatch + buildHysteriaProxy)

Test plan

  • go build ./... + go vet ./sub/... clean
  • Hysteria inbound without External Proxy → subscription link uses request host + inbound.Port (unchanged from before)
  • Hysteria inbound with External Proxy entries → one hysteria2://… link per entry, each pointing at its own dest:port with the configured remark suffix
  • Salamander obfs password on the inbound ends up as obfs=salamander&obfs-password=… in every emitted link
  • Clash subscription now contains type: hysteria2 (or hysteria for v1) proxies for every Hysteria inbound, with password / auth-str / sni / alpn / skip-cert-verify / obfs / obfs-password populated from the inbound
  • External Proxy on a Hysteria inbound produces one Clash proxy per entry (via the existing getProxies fanout, now that buildProxy stops dropping Hysteria)
  • Non-Hysteria inbounds unchanged (vmess/vless/trojan/ss paths never touched)

🔄 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/4073 **Author:** [@pwnnex](https://github.com/pwnnex) **Created:** 4/21/2026 **Status:** ✅ Merged **Merged:** 4/22/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/hysteria-external-proxy-and-clash` --- ### 📝 Commits (3) - [`3213d62`](https://github.com/MHSanaei/3x-ui/commit/3213d62750e488a0bb9f5219b5acea9b8e13d0c1) Fix Hysteria External Proxy + include Hysteria in Clash subscription (#4053) - [`e20a8c7`](https://github.com/MHSanaei/3x-ui/commit/e20a8c7ef8b06a149c0a26ae29025bee9b447a91) gofmt: align map keys in buildHysteriaProxy - [`863f767`](https://github.com/MHSanaei/3x-ui/commit/863f76783802f64fdd58cb7b5e09b124e39fb2c5) Merge branch 'main' into fix/hysteria-external-proxy-and-clash ### 📊 Changes **2 files changed** (+135 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `sub/subClashService.go` (+86 -0) 📝 `sub/subService.go` (+49 -3) </details> ### 📄 Description Closes #4053. Two related gaps on the Hysteria side of the subscription layer. ## 1. `genHysteriaLink` ignored `externalProxy` `sub/subService.go → genHysteriaLink` built its link as ```go link := fmt.Sprintf("%s://%s@%s:%d", protocol, auth, s.address, inbound.Port) ``` with no reference to the inbound's `externalProxy` array. Every other generator (`genVmessLink`, `genVlessLink`, `genTrojanLink`, `genShadowsocksLink`) iterates that array and emits one link per entry, substituting `dest` / `port` / `remark`. Hysteria was the outlier, so admins who pointed a Hysteria inbound at an alternate endpoint (typical scenario: a CDN hostname that forwards UDP to the node) still got a subscription with the original server address. The issue reporter ran into exactly this. Fix: mirror the pattern. When `externalProxy` is non-empty, fan out — one link per entry — substituting `dest` / `port` and using the entry's remark as a suffix. If the array is absent or empty, keep the previous behaviour (use the request host + `inbound.Port`). While I was in there, I also propagated the salamander obfs password (`finalmask.udp[salamander].settings.password`) as `obfs=salamander&obfs-password=…`. The panel-side link generator (`web/assets/js/model/inbound.js → genHysteriaLink`) already emits these query params, so the subscription output was just lagging. ## 2. Hysteria missing from Clash subscription `sub/subClashService.go → buildProxy` had a protocol switch with cases for VMESS / VLESS / Trojan / Shadowsocks and a `default: return nil`. Hysteria inbounds fell into the default branch and silently vanished from the YAML — the user saw every other protocol in their Clash config except the Hysteria ones. Fix: route Hysteria through a dedicated `buildHysteriaProxy` helper *before* the existing `applyTransport` / `applySecurity` helpers run. Those helpers model xray `streamSettings.network` / `streamSettings.security`, which Hysteria doesn't use — Hysteria carries its own UDP transport and TLS handshake. The helper reads `inbound.StreamSettings` directly instead of going through `streamData` / `tlsData`, because those prune fields (`allowInsecure`, the salamander `finalmask.udp` block) that the mihomo Hysteria proxy needs preserved. Output shape matches mihomo's docs: ```yaml - name: <remark> type: hysteria2 # or "hysteria" for v1 inbounds server: <ext-proxy-host or inbound.Listen> port: <ext-proxy-port or inbound.Port> password: <client.Auth> # "auth-str" for v1 udp: true sni: <tlsSettings.serverName> alpn: [h3] # whatever tlsSettings.alpn has skip-cert-verify: true # iff tlsSettings.settings.allowInsecure client-fingerprint: chrome # iff tlsSettings.settings.fingerprint set obfs: salamander obfs-password: <finalmask.udp[salamander].settings.password> ``` The existing `getProxies` fanout over `externalProxy` is untouched and plugs in automatically, so once Hysteria is recognised by `buildProxy` it also picks up External Proxy entries in the Clash output. ## Diff size `sub/subService.go`: `genHysteriaLink` rewritten (+49 −3) `sub/subClashService.go`: +86 (early Hysteria dispatch + `buildHysteriaProxy`) ## Test plan - [x] `go build ./...` + `go vet ./sub/...` clean - [x] Hysteria inbound **without** External Proxy → subscription link uses request host + `inbound.Port` (unchanged from before) - [x] Hysteria inbound **with** External Proxy entries → one `hysteria2://…` link per entry, each pointing at its own `dest:port` with the configured remark suffix - [x] Salamander obfs password on the inbound ends up as `obfs=salamander&obfs-password=…` in every emitted link - [x] Clash subscription now contains `type: hysteria2` (or `hysteria` for v1) proxies for every Hysteria inbound, with `password` / `auth-str` / `sni` / `alpn` / `skip-cert-verify` / `obfs` / `obfs-password` populated from the inbound - [x] External Proxy on a Hysteria inbound produces one Clash proxy per entry (via the existing `getProxies` fanout, now that `buildProxy` stops dropping Hysteria) - [x] Non-Hysteria inbounds unchanged (vmess/vless/trojan/ss paths never touched) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:48:01 +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#5590
No description provided.