[PR #6505] [MERGED] fix(link): rebuild shadowsocks tcp/http obfuscation on import #6317

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/6505
Author: @BlindMaster24
Created: 9/13/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @MHSanaei

Base: main ← Head: fix/link-shadowsocks-plugin-import


📝 Commits (2)

  • 8bcdbb8 fix(link): rebuild shadowsocks tcp/http obfuscation on import
  • 0573de8 fix(link): map the SIP002 plugin in both importers

📊 Changes

5 files changed (+187 additions, -0 deletions)

View changed files

📝 frontend/src/lib/xray/outbound-link-parser.ts (+22 -0)
📝 frontend/src/test/outbound-link-parser.test.ts (+21 -0)
➕ internal/sub/shadowsocks_plugin_import_test.go (+49 -0)
📝 internal/util/link/outbound.go (+51 -0)
📝 internal/util/link/outbound_test.go (+44 -0)

📄 Description

Summary

ParseLink now rebuilds the tcp/http response header a shadowsocks link describes through the SIP002 plugin=obfs-local parameter. Importing a link the panel had just exported no longer throws the obfuscation away.

Why

genShadowsocksLink exports tcp/http obfuscation only as the SIP002 plugin parameter. That is deliberate — internal/sub/service.go:1303-1310 says why:

// SIP002 clients (v2rayN) ignore the xray-native type/headerType/host/path
// params and only read `plugin`. Re-encode a TCP http header as obfs-local so
// they build a matching tcp/http outbound (v2rayN forces request path "/").
if streamNetwork == "tcp" && params["headerType"] == "http" {
    delete(params, "type")
    delete(params, "headerType")
    delete(params, "host")
    delete(params, "path")
    params["plugin"] = "obfs-local;obfs=http;obfs-host=" + host
}

The importer read none of it. parseShadowsocks passed only type/security/sni/alpn/fp into applyTransport, and the emitter had just deleted four of those, so a link round-tripped through the panel lost the one thing that made it work.

Reproduced against the current main with the export path itself, not a hand-written string:

exported: ss://YWVzLTI1Ni1nY206Y2xpZW50cGFzcw@203.0.113.1:8388?plugin=obfs-local%3Bobfs%3Dhttp%3Bobfs-host%3Dobfs.example.com#user
imported: {"network":"tcp","security":"none","tcpSettings":{"header":{"type":"none"}}}

The header is none. The inbound behind that link speaks tcp/header.type: http, so the imported outbound cannot connect to it.

Operator scenario. Someone runs a 3x-ui panel with a shadowsocks inbound using TCP + HTTP-header obfuscation (a common way to make an SS inbound look like plain HTTP). They hand out the share link, or point a second 3x-ui node at it with an external subscription. Both import paths end in link.ParseLink — internal/sub/external_config.go:216 for a pasted link, internal/web/service/outbound_subscription.go:394 for a fetched subscription. What lands in the second panel is a plain-TCP SS outbound: it saves fine, shows no error, and simply never connects. The same link in v2rayN works, because v2rayN reads plugin, so the first panel looks correct and the second one looks broken. The other direction — the panel's own JSON/Clash output — never goes through ParseLink and is unaffected.

This is the same class as #6467, which preserved the shadowsocks TLS query params on import in this function; the plugin parameter was the remaining unread one.

What changed

applyObfsLocalPlugin maps plugin=obfs-local;obfs=http;obfs-host=<host> onto type=tcp, headerType=http, host=<host> — exactly the four keys the emitter deleted, so the existing applyTransport branch rebuilds tcpSettings.header (with path: ["/"], matching the emitter's note that SIP002 clients force /).

  • Only obfs=http is mapped. obfs=tls and third-party plugins (v2ray-plugin, …) are left alone, because Xray has no header that corresponds to them and guessing would be worse than the current silence. Both cases are asserted.
  • An explicit headerType/type=http in the link wins; the helper returns early rather than overwriting it.
  • Credentials, mport handling, the identity string (and therefore import dedup) and every other protocol are untouched.

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?

Two tests, and both were watched going red without the fix (by running them against main's outbound.go):

  • internal/sub/shadowsocks_plugin_import_test.go — the round trip, driven through the real exporter: genShadowsocksLink on a tcp/http inbound, then link.ParseLink on the result. Asserts header.type == "http" and the obfs-host survives. Without the fix it fails with {"header":{"type":"none"}}.
  • internal/util/link/outbound_test.go — TestParseShadowsocksObfsLocalPlugin, a table over the three plugin shapes: obfs=http becomes the header, obfs=tls and v2ray-plugin stay none. Without the fix the first row fails with header = map[type:none], want type "http".

Local run: this machine has no C compiler, so the Go tests ran with a pure-Go SQLite driver (modernc.org/sqlite) substituted behind go build -overlay, whose only entries are internal/database's driver call sites. go test ./internal/util/link/ ./internal/sub/ — both green; gofmt and go vet clean on both packages. The existing shadowsocks cases in TestParseShadowsocks, including the two that already carried a plugin= query, still pass; they only asserted credentials, so the new mapping is the behaviour change they never pinned.

Screenshots / recordings

N/A — wire format, covered above.

Breaking changes

None.

Checklist

  • I tested the change locally and confirmed the described behavior. (pure-Go driver behind an overlay, see above)
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally. (as-is they need the CGo driver; CI covers that)
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass. (no frontend change in this PR)
  • I updated the Wiki / README / API docs if user-facing behavior changed. (no docs describe this import detail)
  • 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/6505 **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/link-shadowsocks-plugin-import` --- ### 📝 Commits (2) - [`8bcdbb8`](https://github.com/MHSanaei/3x-ui/commit/8bcdbb8f7d025b795f176997dfc56954a0523526) fix(link): rebuild shadowsocks tcp/http obfuscation on import - [`0573de8`](https://github.com/MHSanaei/3x-ui/commit/0573de866dcc6ad3358a1be9bfb3c2750eb813b6) fix(link): map the SIP002 plugin in both importers ### 📊 Changes **5 files changed** (+187 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/lib/xray/outbound-link-parser.ts` (+22 -0) 📝 `frontend/src/test/outbound-link-parser.test.ts` (+21 -0) ➕ `internal/sub/shadowsocks_plugin_import_test.go` (+49 -0) 📝 `internal/util/link/outbound.go` (+51 -0) 📝 `internal/util/link/outbound_test.go` (+44 -0) </details> ### 📄 Description ## Summary `ParseLink` now rebuilds the tcp/http response header a shadowsocks link describes through the SIP002 `plugin=obfs-local` parameter. Importing a link the panel had just exported no longer throws the obfuscation away. ## Why `genShadowsocksLink` exports tcp/http obfuscation **only** as the SIP002 plugin parameter. That is deliberate — `internal/sub/service.go:1303-1310` says why: ```go // SIP002 clients (v2rayN) ignore the xray-native type/headerType/host/path // params and only read `plugin`. Re-encode a TCP http header as obfs-local so // they build a matching tcp/http outbound (v2rayN forces request path "/"). if streamNetwork == "tcp" && params["headerType"] == "http" { delete(params, "type") delete(params, "headerType") delete(params, "host") delete(params, "path") params["plugin"] = "obfs-local;obfs=http;obfs-host=" + host } ``` The importer read none of it. `parseShadowsocks` passed only `type`/`security`/`sni`/`alpn`/`fp` into `applyTransport`, and the emitter had just deleted four of those, so a link round-tripped through the panel lost the one thing that made it work. Reproduced against the current `main` with the export path itself, not a hand-written string: ``` exported: ss://YWVzLTI1Ni1nY206Y2xpZW50cGFzcw@203.0.113.1:8388?plugin=obfs-local%3Bobfs%3Dhttp%3Bobfs-host%3Dobfs.example.com#user imported: {"network":"tcp","security":"none","tcpSettings":{"header":{"type":"none"}}} ``` The header is `none`. The inbound behind that link speaks `tcp`/`header.type: http`, so the imported outbound cannot connect to it. **Operator scenario.** Someone runs a 3x-ui panel with a shadowsocks inbound using TCP + HTTP-header obfuscation (a common way to make an SS inbound look like plain HTTP). They hand out the share link, or point a second 3x-ui node at it with an external subscription. Both import paths end in `link.ParseLink` — `internal/sub/external_config.go:216` for a pasted link, `internal/web/service/outbound_subscription.go:394` for a fetched subscription. What lands in the second panel is a plain-TCP SS outbound: it saves fine, shows no error, and simply never connects. The same link in v2rayN works, because v2rayN reads `plugin`, so the first panel looks correct and the second one looks broken. The other direction — the panel's own JSON/Clash output — never goes through `ParseLink` and is unaffected. This is the same class as #6467, which preserved the shadowsocks TLS query params on import in this function; the plugin parameter was the remaining unread one. ## What changed `applyObfsLocalPlugin` maps `plugin=obfs-local;obfs=http;obfs-host=<host>` onto `type=tcp`, `headerType=http`, `host=<host>` — exactly the four keys the emitter deleted, so the existing `applyTransport` branch rebuilds `tcpSettings.header` (with `path: ["/"]`, matching the emitter's note that SIP002 clients force `/`). - Only `obfs=http` is mapped. `obfs=tls` and third-party plugins (`v2ray-plugin`, …) are left alone, because Xray has no header that corresponds to them and guessing would be worse than the current silence. Both cases are asserted. - An explicit `headerType`/`type=http` in the link wins; the helper returns early rather than overwriting it. - Credentials, `mport` handling, the `identity` string (and therefore import dedup) and every other protocol are untouched. ## 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? Two tests, and both were watched going red without the fix (by running them against `main`'s `outbound.go`): - `internal/sub/shadowsocks_plugin_import_test.go` — the round trip, driven through the real exporter: `genShadowsocksLink` on a tcp/http inbound, then `link.ParseLink` on the result. Asserts `header.type == "http"` and the `obfs-host` survives. Without the fix it fails with `{"header":{"type":"none"}}`. - `internal/util/link/outbound_test.go` — `TestParseShadowsocksObfsLocalPlugin`, a table over the three plugin shapes: `obfs=http` becomes the header, `obfs=tls` and `v2ray-plugin` stay `none`. Without the fix the first row fails with `header = map[type:none], want type "http"`. Local run: this machine has no C compiler, so the Go tests ran with a pure-Go SQLite driver (`modernc.org/sqlite`) substituted behind `go build -overlay`, whose only entries are `internal/database`'s driver call sites. `go test ./internal/util/link/ ./internal/sub/` — both green; `gofmt` and `go vet` clean on both packages. The existing shadowsocks cases in `TestParseShadowsocks`, including the two that already carried a `plugin=` query, still pass; they only asserted credentials, so the new mapping is the behaviour change they never pinned. ## Screenshots / recordings N/A — wire format, covered above. ## Breaking changes None. ## Checklist - [x] I tested the change locally and confirmed the described behavior. (pure-Go driver behind an overlay, see above) - [x] I added or updated tests for the new behavior (when applicable). - [ ] `go build ./...` and the test suite pass locally. (as-is they need the CGo driver; CI covers that) - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. (no frontend change in this PR) - [x] I updated the Wiki / README / API docs if user-facing behavior changed. (no docs describe this import detail) - [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#6317
No description provided.