[GH-ISSUE #6477] [Bug]: Go share-link importer drops verifyPeerCertByName (vcn); TS keeps it #4371

Closed
opened 2026-10-31 20:39:11 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @mrchatam on GitHub (Sep 11, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6477

Describe the bug

When an inbound sets verifyPeerCertByName, the panel's share-link generators emit vcn on the query string (internal/sub/service.go). The TypeScript importer applies it (frontend/src/lib/xray/outbound-link-parser.ts sets tls.verifyPeerCertByName from vcn), but the Go importer's applySecurity does not — it reads sni / fp / alpn / ech / pcs only and leaves verifyPeerCertByName as the empty string seeded by buildStream.

Consequence: the same share link produces different TLS settings depending on which importer runs. Paths that use the Go parser (including external-link JSON subscription materialization via internal/sub/external_config.go → link parse → json_service.go) emit an outbound that verifies against the wrong name and fails the handshake when the cert CN differs from the SNI.

Note: parseHysteria2 in the same Go file does read vcn; the omission is specific to applySecurity (used by VLESS / Trojan / Shadowsocks).

How to reproduce the problem

  1. Create a TLS inbound whose certificate CN differs from the SNI clients use, and set verifyPeerCertByName to that CN.
  2. Copy a VLESS or Trojan share link; confirm vcn=<cn> is present in the query.
  3. Import the link through a Go path (e.g. add it as an external proxy / JSON subscription source that round-trips through internal/util/link).
  4. Compare with importing the same link in the panel UI (TS parser).

Expected behavior

Go and TS importers both set tlsSettings.verifyPeerCertByName from vcn, matching what the generator emitted.

Actual behavior

TS import keeps vcn; Go import drops it. Clients built from the Go path fail TLS when the peer cert name must be checked explicitly.

File pointers

  • Generator: internal/sub/service.go (sets params["vcn"])
  • Go gap: internal/util/link/outbound.go → applySecurity (tls branch)
  • TS OK: frontend/src/lib/xray/outbound-link-parser.ts (~line applying vcn)
  • Hysteria contrast: same Go file, parseHysteria2 already maps vcn

3x-ui version

main (current default branch)

Suggested fix size

Small: one assignment in applySecurity's TLS branch (tls["verifyPeerCertByName"] = p.Get("vcn")), plus a regression test next to the existing link-parser coverage.

Originally created by @mrchatam on GitHub (Sep 11, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6477 ### Describe the bug When an inbound sets `verifyPeerCertByName`, the panel's share-link generators emit `vcn` on the query string (`internal/sub/service.go`). The TypeScript importer applies it (`frontend/src/lib/xray/outbound-link-parser.ts` sets `tls.verifyPeerCertByName` from `vcn`), but the Go importer's `applySecurity` does not — it reads `sni` / `fp` / `alpn` / `ech` / `pcs` only and leaves `verifyPeerCertByName` as the empty string seeded by `buildStream`. Consequence: the same share link produces different TLS settings depending on which importer runs. Paths that use the Go parser (including external-link JSON subscription materialization via `internal/sub/external_config.go` → link parse → `json_service.go`) emit an outbound that verifies against the wrong name and fails the handshake when the cert CN differs from the SNI. Note: `parseHysteria2` in the same Go file *does* read `vcn`; the omission is specific to `applySecurity` (used by VLESS / Trojan / Shadowsocks). ### How to reproduce the problem 1. Create a TLS inbound whose certificate CN differs from the SNI clients use, and set `verifyPeerCertByName` to that CN. 2. Copy a VLESS or Trojan share link; confirm `vcn=<cn>` is present in the query. 3. Import the link through a Go path (e.g. add it as an external proxy / JSON subscription source that round-trips through `internal/util/link`). 4. Compare with importing the same link in the panel UI (TS parser). ### Expected behavior Go and TS importers both set `tlsSettings.verifyPeerCertByName` from `vcn`, matching what the generator emitted. ### Actual behavior TS import keeps `vcn`; Go import drops it. Clients built from the Go path fail TLS when the peer cert name must be checked explicitly. ### File pointers - Generator: `internal/sub/service.go` (sets `params["vcn"]`) - Go gap: `internal/util/link/outbound.go` → `applySecurity` (tls branch) - TS OK: `frontend/src/lib/xray/outbound-link-parser.ts` (~line applying `vcn`) - Hysteria contrast: same Go file, `parseHysteria2` already maps `vcn` ### 3x-ui version main (current default branch) ### Suggested fix size Small: one assignment in `applySecurity`'s TLS branch (`tls["verifyPeerCertByName"] = p.Get("vcn")`), plus a regression test next to the existing link-parser coverage.
bsakaguchi 2026-10-31 20:39:11 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Sep 11, 2026):

You are right about the defect, but this is a duplicate: you filed the same report as #6474 one minute earlier (#6474 created 16:53:36Z, this one 16:54:36Z), and #6474 already carries the full analysis. Closing this one and keeping #6474 as the tracking issue — nothing is lost.

The shared root cause, confirmed in the source

applySecurity never reads vcn, so the empty seed survives:

// internal/util/link/outbound.go:658  func applySecurity
case "tls":
    tls := stream["tlsSettings"].(map[string]any)
    tls["serverName"] = p.Get("sni")
    tls["fingerprint"] = p.Get("fp")
    if alpn := p.Get("alpn"); alpn != "" {
        tls["alpn"] = splitComma(alpn)
    }
    tls["echConfigList"] = p.Get("ech")
    tls["pinnedPeerCertSha256"] = p.Get("pcs")

The seed is "verifyPeerCertByName": "" at internal/util/link/outbound.go:583. The generator emits the param — params["vcn"] = vcn in applyShareTLSParams (internal/sub/service.go:1676-1678), right next to the params["pcs"] the importer does read. Hysteria2 maps it (internal/util/link/outbound.go:455) and so does TS (frontend/src/lib/xray/outbound-link-parser.ts:399). Still present at the tip of main (0a2cd789).

Two corrections to this report, both already recorded on #6474

  1. Shadowsocks is not an applySecurity consumer. The only callers are parseVless (internal/util/link/outbound.go:274) and parseTrojan (:316). parseShadowsocks throws the entire query away before parsing — if i := strings.Index(link, "?"); i >= 0 { link = link[:i] } (internal/util/link/outbound.go:345-347) — and returns an outbound with no streamSettings at all, so it loses sni/fp/pcs too, not just vcn. That is a separate, wider gap.
  2. vmess drops vcn in a second place. applyVmessTLSParams writes obj["vcn"] (internal/sub/service.go:1711-1713), but parseVmess has its own inline TLS block mapping only sni/fp/alpn (internal/util/link/outbound.go:201-208). A one-line fix in applySecurity leaves that one broken.

Follow #6474 for the rest.

Verdict: Duplicate
Severity: Medium
Confidence: High
Root cause: applySecurity in internal/util/link/outbound.go:658 (TLS branch, lines 661-669) never reads the vcn query param, so the "verifyPeerCertByName": "" seeded by buildStream (internal/util/link/outbound.go:583) survives every Go parse of a vless/trojan link. Introduced by 7c888946 ("feat(tls,reality): port xray TLS/REALITY fields…"), whose file list contains no internal/util/link/ path while it added vcn to both generators and to the TS parser; 5e1cb769 (#5970) later fixed only the Hysteria2 branch.
Already fixed: Still present on the default branch (0a2cd789).
Duplicate of: #6474 — identical report by the same author one minute earlier, same root cause (applySecurity omits vcn), already analysed there.
Evidence: internal/util/link/outbound.go:658-679 (applySecurity, reads pcs but not vcn); :583 (empty seed); :455 (Hysteria2 maps vcn); :201-208 (vmess drops it); :274, :316 (the only applySecurity callers); :345-347 (parseShadowsocks discards the query); internal/sub/service.go:1676-1678 and :1711-1713 (generators emit vcn); frontend/src/lib/xray/outbound-link-parser.ts:399 (TS applies it); consumers internal/sub/json_service.go:182 and internal/web/service/outbound_subscription.go:394; tests internal/util/link/outbound_helpers_test.go:125 (TLS fields pinned, no vcn case) and :193 (TestParse_Hysteria2VerifyPeerCertByName); commits 7c888946, 5e1cb769.
Not determined: None for the duplicate call — both issues state the same defect at the same lines.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:5637901419 --> @github-actions[bot] commented on GitHub (Sep 11, 2026): You are right about the defect, but this is a duplicate: you filed the same report as #6474 one minute earlier (#6474 created `16:53:36Z`, this one `16:54:36Z`), and #6474 already carries the full analysis. Closing this one and keeping #6474 as the tracking issue — nothing is lost. ### The shared root cause, confirmed in the source `applySecurity` never reads `vcn`, so the empty seed survives: ```go // internal/util/link/outbound.go:658 func applySecurity case "tls": tls := stream["tlsSettings"].(map[string]any) tls["serverName"] = p.Get("sni") tls["fingerprint"] = p.Get("fp") if alpn := p.Get("alpn"); alpn != "" { tls["alpn"] = splitComma(alpn) } tls["echConfigList"] = p.Get("ech") tls["pinnedPeerCertSha256"] = p.Get("pcs") ``` The seed is `"verifyPeerCertByName": ""` at `internal/util/link/outbound.go:583`. The generator emits the param — `params["vcn"] = vcn` in `applyShareTLSParams` (`internal/sub/service.go:1676-1678`), right next to the `params["pcs"]` the importer *does* read. Hysteria2 maps it (`internal/util/link/outbound.go:455`) and so does TS (`frontend/src/lib/xray/outbound-link-parser.ts:399`). Still present at the tip of `main` (`0a2cd789`). ### Two corrections to this report, both already recorded on #6474 1. **Shadowsocks is not an `applySecurity` consumer.** The only callers are `parseVless` (`internal/util/link/outbound.go:274`) and `parseTrojan` (`:316`). `parseShadowsocks` throws the entire query away before parsing — `if i := strings.Index(link, "?"); i >= 0 { link = link[:i] }` (`internal/util/link/outbound.go:345-347`) — and returns an outbound with no `streamSettings` at all, so it loses `sni`/`fp`/`pcs` too, not just `vcn`. That is a separate, wider gap. 2. **vmess drops `vcn` in a second place.** `applyVmessTLSParams` writes `obj["vcn"]` (`internal/sub/service.go:1711-1713`), but `parseVmess` has its own inline TLS block mapping only `sni`/`fp`/`alpn` (`internal/util/link/outbound.go:201-208`). A one-line fix in `applySecurity` leaves that one broken. Follow #6474 for the rest. Verdict: Duplicate Severity: Medium Confidence: High Root cause: `applySecurity` in `internal/util/link/outbound.go:658` (TLS branch, lines 661-669) never reads the `vcn` query param, so the `"verifyPeerCertByName": ""` seeded by `buildStream` (`internal/util/link/outbound.go:583`) survives every Go parse of a vless/trojan link. Introduced by `7c888946` ("feat(tls,reality): port xray TLS/REALITY fields…"), whose file list contains no `internal/util/link/` path while it added `vcn` to both generators and to the TS parser; `5e1cb769` (#5970) later fixed only the Hysteria2 branch. Already fixed: Still present on the default branch (`0a2cd789`). Duplicate of: #6474 — identical report by the same author one minute earlier, same root cause (`applySecurity` omits `vcn`), already analysed there. Evidence: `internal/util/link/outbound.go:658-679` (`applySecurity`, reads `pcs` but not `vcn`); `:583` (empty seed); `:455` (Hysteria2 maps `vcn`); `:201-208` (vmess drops it); `:274`, `:316` (the only `applySecurity` callers); `:345-347` (`parseShadowsocks` discards the query); `internal/sub/service.go:1676-1678` and `:1711-1713` (generators emit `vcn`); `frontend/src/lib/xray/outbound-link-parser.ts:399` (TS applies it); consumers `internal/sub/json_service.go:182` and `internal/web/service/outbound_subscription.go:394`; tests `internal/util/link/outbound_helpers_test.go:125` (TLS fields pinned, no `vcn` case) and `:193` (`TestParse_Hysteria2VerifyPeerCertByName`); commits `7c888946`, `5e1cb769`. Not determined: None for the duplicate call — both issues state the same defect at the same lines. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
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#4371
No description provided.