[PR #5676] [MERGED] fix(sub): include native WireGuard clients in Clash and JSON subscriptions #5955

Closed
opened 2026-11-02 04:05:16 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5676
Author: @STRENCH0
Created: 6/30/2026
Status: ✅ Merged
Merged: 7/8/2026
Merged by: @MHSanaei

Base: main ← Head: fix/wireguard-clash-json-sub


📝 Commits (2)

  • 7dd2952 fix(sub): include native WireGuard clients in Clash and JSON subscriptions
  • 9cbb1b5 Merge branch 'main' into fix/wireguard-clash-json-sub

📊 Changes

4 files changed (+275 additions, -0 deletions)

View changed files

📝 internal/sub/clash_service.go (+65 -0)
📝 internal/sub/clash_service_test.go (+79 -0)
📝 internal/sub/json_service.go (+56 -0)
📝 internal/sub/json_service_test.go (+75 -0)

📄 Description

The Clash (buildProxy) and JSON (getConfig) subscription generators had no WireGuard branch, so a native WireGuard inbound's clients were silently dropped: buildProxy hit its default nil case, and getConfig emitted a config with no proxy outbound. Only the raw subscription (genWireguardLink) and external-link Clash path handled WireGuard.

Add a WireGuard case to both generators, mirroring genWireguardLink: the peer public key is derived from the inbound secretKey, while the private key, tunnel address (mihomo ip/ipv6, Xray settings.address), pre-shared key and keep-alive come from the client. The peer routes the full tunnel (0.0.0.0/0, ::/0), which both mihomo and Xray also default to. Field names verified against the mihomo WireGuardOption source and the Xray wireguard outbound schema.

Summary

Native WireGuard inbounds now appear in the Clash and JSON subscriptions. Their clients were previously dropped from both formats.

Why

The Clash (buildProxy) and JSON (getConfig) subscription generators had no WireGuard branch. For a native WireGuard inbound:

  • Clash: buildProxy fell through to its default: return nil, so the client never made it into the YAML (and thus never into the PROXY proxy-group).
  • JSON: getConfig's protocol switch had no wireguard case, so the emitted config had no proxy outbound — an unusable entry.

Only the raw subscription (genWireguardLink) and the external-link Clash path (clashWireguardFromExternal) handled WireGuard, which is why WG clients silently went missing from Clash/JSON subs.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

New table-free unit tests in internal/sub, mirroring the existing generator tests:

  • TestBuildWireguardProxyForClash / TestBuildWireguardProxyForClashNoKey — asserts the mihomo proxy fields (type, server, port, private-key, public-key derived from the inbound secretKey, pre-shared-key, ip/ipv6, mtu, dns, udp) and the keyless → nil path.
  • TestSubJsonServiceWireguard / TestSubJsonServiceWireguardNoKey — asserts the Xray wireguard outbound (secretKey, address, peers[] with publicKey/endpoint/allowedIPs full tunnel/preSharedKey/keepAlive, mtu) and the keyless → nil path.

Field names were verified against the upstream mihomo WireGuardOption source and the Xray wireguard outbound schema.

Full local gate passed:

  • make verify (gen-check, lint, typecheck, test, build) — OK
  • golangci-lint run ./internal/sub/ — 0 issues

Manual testing:
Spun up a 3x-ui panel locally, created a WireGuard connection and a subscription. Verified that clash and json subscriptions now include the WireGuard config

Screenshots / recordings

N/A — no UI changes.

Breaking changes

None.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 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/5676 **Author:** [@STRENCH0](https://github.com/STRENCH0) **Created:** 6/30/2026 **Status:** ✅ Merged **Merged:** 7/8/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/wireguard-clash-json-sub` --- ### 📝 Commits (2) - [`7dd2952`](https://github.com/MHSanaei/3x-ui/commit/7dd2952b52e7eb9a37e81e9039c73c0d606ca4ad) fix(sub): include native WireGuard clients in Clash and JSON subscriptions - [`9cbb1b5`](https://github.com/MHSanaei/3x-ui/commit/9cbb1b51f20b2b20cce55608685e2449d3dd792f) Merge branch 'main' into fix/wireguard-clash-json-sub ### 📊 Changes **4 files changed** (+275 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `internal/sub/clash_service.go` (+65 -0) 📝 `internal/sub/clash_service_test.go` (+79 -0) 📝 `internal/sub/json_service.go` (+56 -0) 📝 `internal/sub/json_service_test.go` (+75 -0) </details> ### 📄 Description The Clash (buildProxy) and JSON (getConfig) subscription generators had no WireGuard branch, so a native WireGuard inbound's clients were silently dropped: buildProxy hit its default nil case, and getConfig emitted a config with no proxy outbound. Only the raw subscription (genWireguardLink) and external-link Clash path handled WireGuard. Add a WireGuard case to both generators, mirroring genWireguardLink: the peer public key is derived from the inbound secretKey, while the private key, tunnel address (mihomo ip/ipv6, Xray settings.address), pre-shared key and keep-alive come from the client. The peer routes the full tunnel (0.0.0.0/0, ::/0), which both mihomo and Xray also default to. Field names verified against the mihomo WireGuardOption source and the Xray wireguard outbound schema. ## Summary Native WireGuard inbounds now appear in the Clash and JSON subscriptions. Their clients were previously dropped from both formats. ## Why The Clash (`buildProxy`) and JSON (`getConfig`) subscription generators had no WireGuard branch. For a native WireGuard inbound: - Clash: `buildProxy` fell through to its `default: return nil`, so the client never made it into the YAML (and thus never into the `PROXY` proxy-group). - JSON: `getConfig`'s protocol switch had no `wireguard` case, so the emitted config had no proxy outbound — an unusable entry. Only the raw subscription (`genWireguardLink`) and the external-link Clash path (`clashWireguardFromExternal`) handled WireGuard, which is why WG clients silently went missing from Clash/JSON subs. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [ ] Xray config generation - [x] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? New table-free unit tests in `internal/sub`, mirroring the existing generator tests: - `TestBuildWireguardProxyForClash` / `TestBuildWireguardProxyForClashNoKey` — asserts the mihomo proxy fields (`type`, `server`, `port`, `private-key`, `public-key` derived from the inbound `secretKey`, `pre-shared-key`, `ip`/`ipv6`, `mtu`, `dns`, `udp`) and the keyless → `nil` path. - `TestSubJsonServiceWireguard` / `TestSubJsonServiceWireguardNoKey` — asserts the Xray `wireguard` outbound (`secretKey`, `address`, `peers[]` with `publicKey`/`endpoint`/`allowedIPs` full tunnel/`preSharedKey`/`keepAlive`, `mtu`) and the keyless → `nil` path. Field names were verified against the upstream mihomo `WireGuardOption` source and the Xray `wireguard` outbound schema. Full local gate passed: - `make verify` (gen-check, lint, typecheck, test, build) — OK - `golangci-lint run ./internal/sub/` — 0 issues Manual testing: Spun up a 3x-ui panel locally, created a WireGuard connection and a subscription. Verified that clash and json subscriptions now include the WireGuard config ## Screenshots / recordings N/A — no UI changes. ## Breaking changes None. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:16 +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#5955
No description provided.