[PR #6508] [MERGED] fix(sub): drop external Clash shadowsocks nodes the panel cannot express #6318

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6508
Author: @BlindMaster24
Created: 9/13/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @MHSanaei

Base: main ← Head: fix/clash-shadowsocks-obfs-gate


📝 Commits (3)

  • fb7045b fix(sub): gate external Clash shadowsocks links like the inbound path
  • 41921df fix(sub): count a dropped external link in the quota header
  • 8dce470 docs(sub): describe clashProxyFromExternal by what it does, not by protocol

📊 Changes

4 files changed (+200 additions, -8 deletions)

View changed files

📝 internal/sub/clash_external.go (+4 -6)
➕ internal/sub/clash_external_quota_test.go (+118 -0)
➕ internal/sub/clash_external_shadowsocks_test.go (+75 -0)
📝 internal/sub/clash_service.go (+3 -2)

📄 Description

Summary

clashProxyFromExternal returned as soon as it had built the shadowsocks proxy, so an ss:// link skipped the transport/security mapping that every other protocol — and the inbound path — goes through.

Why

Pasting an ss:// link into an external Clash subscription produced a proxy built from type/server/port/cipher/password alone. Two user-visible consequences:

1. TCP/HTTP obfuscation was ignored, and the node was not dropped. mihomo cannot express an xray tcpSettings.header.type=http on a shadowsocks proxy, which is why applyTransport returns false and the inbound path (buildProxy → applyTransport → getProxies) omits such a node: the YAML ships with a working set of proxies. The external-link path emitted it anyway, so mihomo opens a plain shadowsocks stream at a server that requires the HTTP header. The node appears in the subscription, the client shows it, and it silently never connects — the same failure mode as #6505, one layer further along. Pasting the identical node as an inbound and as a link produced two mutually inconsistent configs.

2. TLS was silently stripped. For security=tls the link path never called applySecurity, so the proxy carried no tls: true / servername — a plaintext stream at a TLS listener.

3. And once the node is dropped, it took the client's quota with it. The client email that feeds AggregateTrafficByEmails was recorded only when a link produced a proxy (clash_service.go:91-93), so a dropped node also disappeared from the Subscription-Userinfo header — a two-client subscription served A's numbers as the whole subscription's numbers. The !ext.Active branch already counted an email without a proxy, so the rule is now unconditional; that fixes the same under-report for the vmess/vless/trojan links that were already droppable (?type=kcp, unknown security=).

The panel's own genShadowsocksLink writes obfs as plugin=obfs-local;obfs=http;obfs-host=… (SIP002, pinned by TestShadowsocksTcpHttpHeaderUsesObfsLocalPlugin). #6505 maps that plugin onto the tcp/http header on import, so both spellings of the same link now reach this gate. The xray-native spelling (?type=tcp&headerType=http) reaches it on main today, which is what the test below uses, so this PR stands on its own.

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 TestClashExternalShadowsocksMatchesInboundPath builds the same shadowsocks node twice — once as an inbound through buildProxy, once as a share link through clashProxyFromExternal — and requires the two results to agree, for three links:

link expected
?type=tcp (plain) both build the same proxy
?type=tcp&headerType=http&host=test both dropped
?type=tcp&security=tls&sni=ss.sni both build the same proxy, with TLS

Before the fix, all three rows fail — the interesting one is the obfs row, where the inbound path returns nil and the link path returns a proxy:

tcp_http_header: not representable in clash, want both dropped:
  inbound map[string]interface {}(nil)
  link    map[string]interface {}{"cipher":"aes-256-gcm", "name":"external",
          "password":"clientpw", "port":8443, "server":"203.0.113.1",
          "type":"ss", "udp":true}
plain tcp: inbound {… "network":"tcp", "tls":false …} != link {… no network/tls …}
tls:       inbound {… "servername":"ss.sni", "tls":true …} != link {… no tls …}

The fix is the ss case no longer returning early, so it falls into the shared transport/security tail; all three rows then pass, with the link and inbound proxies deep-equal apart from name.

TestClashQuotaHeaderCountsDroppedExternalLink drives the whole HTTP path: a subscription with client A on an inbound (11/22/1024) and client B on an obfs ss:// link (100/200/2048). Without the quota change the header is upload=11; download=22; total=1024 — A alone — and with it upload=111; download=222; total=3072. TestClashAllUnrepresentableNodesAnswerAlike pins that a subscription with nothing representable answers the same way whether the node came from an inbound or an external link (it compares the two responses instead of asserting a particular status).

  • go test ./internal/sub/ — ok (39s)
  • go test ./internal/util/link/ — ok
  • go vet ./internal/sub/ — clean
  • gofmt -l internal/sub/ internal/util/link/ — clean

There is no C toolchain on this machine, so the CGo SQLite driver cannot build here: I ran the packages with CGO_ENABLED=0 plus an overlay replacing the three CGo SQLite call sites in internal/database with a pure-Go driver. Every file in this PR is the real one, unmodified by the overlay. CI stays the authority on go build ./... with the real driver.

Screenshots / recordings

N/A (no UI change).

Breaking changes

None for existing working subscriptions. Two behaviour changes worth stating plainly:

  • An external ss:// node whose transport Clash cannot express is now dropped from the profile, exactly as the same node as an inbound always has been. A subscription whose only node was such a link answers 404 with an empty body instead of serving a profile with one non-connecting proxy — the same answer the inbound path gives for the same node, and what an external vmess/vless/trojan link with ?type=kcp already gets on main. Clients keep the profile they last fetched.
  • security=tls shadowsocks links gain tls: true / servername, and a dropped external node still contributes to Subscription-Userinfo. The quota header of a mixed subscription changes (up) as a result.

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. — no C compiler here, ran with the cgo-free overlay described above; CI verifies the real build.
  • 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. — N/A, no endpoints or settings 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/6508 **Author:** [@BlindMaster24](https://github.com/BlindMaster24) **Created:** 9/13/2026 **Status:** ✅ Merged **Merged:** 9/13/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/clash-shadowsocks-obfs-gate` --- ### 📝 Commits (3) - [`fb7045b`](https://github.com/MHSanaei/3x-ui/commit/fb7045b9389408ce0aa6c918e522171a8a1d4fad) fix(sub): gate external Clash shadowsocks links like the inbound path - [`41921df`](https://github.com/MHSanaei/3x-ui/commit/41921df36ef6e2e19924282e1d9f8a023e2435c9) fix(sub): count a dropped external link in the quota header - [`8dce470`](https://github.com/MHSanaei/3x-ui/commit/8dce470f706dac8dc7d7c990dc5275e5bcbe34c3) docs(sub): describe clashProxyFromExternal by what it does, not by protocol ### 📊 Changes **4 files changed** (+200 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `internal/sub/clash_external.go` (+4 -6) ➕ `internal/sub/clash_external_quota_test.go` (+118 -0) ➕ `internal/sub/clash_external_shadowsocks_test.go` (+75 -0) 📝 `internal/sub/clash_service.go` (+3 -2) </details> ### 📄 Description ## Summary `clashProxyFromExternal` returned as soon as it had built the shadowsocks proxy, so an `ss://` link skipped the transport/security mapping that every other protocol — and the inbound path — goes through. ## Why Pasting an `ss://` link into an external Clash subscription produced a proxy built from `type/server/port/cipher/password` alone. Two user-visible consequences: **1. TCP/HTTP obfuscation was ignored, and the node was not dropped.** mihomo cannot express an xray `tcpSettings.header.type=http` on a shadowsocks proxy, which is why `applyTransport` returns false and the inbound path (`buildProxy` → `applyTransport` → `getProxies`) *omits* such a node: the YAML ships with a working set of proxies. The external-link path emitted it anyway, so mihomo opens a plain shadowsocks stream at a server that requires the HTTP header. The node appears in the subscription, the client shows it, and it silently never connects — the same failure mode as #6505, one layer further along. Pasting the identical node as an inbound and as a link produced two mutually inconsistent configs. **2. TLS was silently stripped.** For `security=tls` the link path never called `applySecurity`, so the proxy carried no `tls: true` / `servername` — a plaintext stream at a TLS listener. **3. And once the node is dropped, it took the client's quota with it.** The client email that feeds `AggregateTrafficByEmails` was recorded only when a link produced a proxy (`clash_service.go:91-93`), so a dropped node also disappeared from the `Subscription-Userinfo` header — a two-client subscription served A's numbers as the whole subscription's numbers. The `!ext.Active` branch already counted an email without a proxy, so the rule is now unconditional; that fixes the same under-report for the vmess/vless/trojan links that were already droppable (`?type=kcp`, unknown `security=`). The panel's own `genShadowsocksLink` writes obfs as `plugin=obfs-local;obfs=http;obfs-host=…` (SIP002, pinned by `TestShadowsocksTcpHttpHeaderUsesObfsLocalPlugin`). #6505 maps that plugin onto the tcp/http header on import, so both spellings of the same link now reach this gate. The xray-native spelling (`?type=tcp&headerType=http`) reaches it on `main` today, which is what the test below uses, so this PR stands on its own. ## 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 `TestClashExternalShadowsocksMatchesInboundPath` builds the same shadowsocks node twice — once as an inbound through `buildProxy`, once as a share link through `clashProxyFromExternal` — and requires the two results to agree, for three links: | link | expected | | --- | --- | | `?type=tcp` (plain) | both build the same proxy | | `?type=tcp&headerType=http&host=test` | both dropped | | `?type=tcp&security=tls&sni=ss.sni` | both build the same proxy, with TLS | Before the fix, all three rows fail — the interesting one is the obfs row, where the inbound path returns `nil` and the link path returns a proxy: ``` tcp_http_header: not representable in clash, want both dropped: inbound map[string]interface {}(nil) link map[string]interface {}{"cipher":"aes-256-gcm", "name":"external", "password":"clientpw", "port":8443, "server":"203.0.113.1", "type":"ss", "udp":true} plain tcp: inbound {… "network":"tcp", "tls":false …} != link {… no network/tls …} tls: inbound {… "servername":"ss.sni", "tls":true …} != link {… no tls …} ``` The fix is the `ss` case no longer returning early, so it falls into the shared transport/security tail; all three rows then pass, with the link and inbound proxies deep-equal apart from `name`. `TestClashQuotaHeaderCountsDroppedExternalLink` drives the whole HTTP path: a subscription with client A on an inbound (11/22/1024) and client B on an obfs `ss://` link (100/200/2048). Without the quota change the header is `upload=11; download=22; total=1024` — A alone — and with it `upload=111; download=222; total=3072`. `TestClashAllUnrepresentableNodesAnswerAlike` pins that a subscription with nothing representable answers the same way whether the node came from an inbound or an external link (it compares the two responses instead of asserting a particular status). - `go test ./internal/sub/` — ok (39s) - `go test ./internal/util/link/` — ok - `go vet ./internal/sub/` — clean - `gofmt -l internal/sub/ internal/util/link/` — clean There is no C toolchain on this machine, so the CGo SQLite driver cannot build here: I ran the packages with `CGO_ENABLED=0` plus an overlay replacing the three CGo SQLite call sites in `internal/database` with a pure-Go driver. Every file in this PR is the real one, unmodified by the overlay. CI stays the authority on `go build ./...` with the real driver. ## Screenshots / recordings N/A (no UI change). ## Breaking changes None for existing working subscriptions. Two behaviour changes worth stating plainly: - An external `ss://` node whose transport Clash cannot express is now dropped from the profile, exactly as the same node as an inbound always has been. A subscription whose *only* node was such a link answers 404 with an empty body instead of serving a profile with one non-connecting proxy — the same answer the inbound path gives for the same node, and what an external vmess/vless/trojan link with `?type=kcp` already gets on `main`. Clients keep the profile they last fetched. - `security=tls` shadowsocks links gain `tls: true` / `servername`, and a dropped external node still contributes to `Subscription-Userinfo`. The quota header of a mixed subscription changes (up) as a result. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [ ] `go build ./...` and the test suite pass locally. — no C compiler here, ran with the cgo-free overlay described above; CI verifies the real build. - [ ] 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. — N/A, no endpoints or settings 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:07:54 +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#6318
No description provided.