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

Closed
opened 2026-10-31 20:39:10 +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/6474

Describe the bug

Share links emit vcn when the inbound has verifyPeerCertByName set (cert CN differs from SNI). The TypeScript outbound importer applies it; the Go importer's shared applySecurity helper does not. External-link / JSON subscription paths that parse links in Go therefore emit outbounds that fail TLS when the peer cert name must be checked explicitly.

How to reproduce the problem

  1. Configure an inbound with TLS and verifyPeerCertByName set to a name that differs from SNI.
  2. Copy a client share link; confirm the query contains vcn=... (generator: internal/sub/service.go sets params["vcn"]).
  3. Import the same link:
    • via the panel UI (TS parser) → outbound has tlsSettings.verifyPeerCertByName set.
    • via a Go parse path (e.g. external subscription / internal/util/link used from internal/sub/external_config.go) → verifyPeerCertByName stays "".
  4. Client using the Go-parsed outbound fails the handshake on cert-name mismatch; TS-imported outbound works.

Expected behavior

Go and TS importers both apply vcn → tlsSettings.verifyPeerCertByName for TLS links (same as Hysteria already does in Go at parseHysteria2).

Actual behavior

applySecurity reads sni / fp / alpn / ech / pcs only and leaves the empty verifyPeerCertByName seeded by buildStream. TS applySecurityParams sets tls.verifyPeerCertByName from vcn.

File pointers (main @ 0a2cd789ba)

  • Generator: internal/sub/service.go (emits params["vcn"] for TLS inbounds with verifyPeerCertByName).
  • Go drop: internal/util/link/outbound.go → applySecurity TLS branch (no vcn read). Contrast: Hysteria path already maps vcn.
  • TS keep: frontend/src/lib/xray/outbound-link-parser.ts → applySecurityParams sets tls.verifyPeerCertByName = params.get('vcn').

Suggested fix size

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

3x-ui version

main (post-3.7.0)

Originally created by @mrchatam on GitHub (Sep 11, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6474 ### Describe the bug Share links emit `vcn` when the inbound has `verifyPeerCertByName` set (cert CN differs from SNI). The TypeScript outbound importer applies it; the Go importer's shared `applySecurity` helper does not. External-link / JSON subscription paths that parse links in Go therefore emit outbounds that fail TLS when the peer cert name must be checked explicitly. ### How to reproduce the problem 1. Configure an inbound with TLS and `verifyPeerCertByName` set to a name that differs from SNI. 2. Copy a client share link; confirm the query contains `vcn=...` (generator: `internal/sub/service.go` sets `params["vcn"]`). 3. Import the same link: - via the panel UI (TS parser) → outbound has `tlsSettings.verifyPeerCertByName` set. - via a Go parse path (e.g. external subscription / `internal/util/link` used from `internal/sub/external_config.go`) → `verifyPeerCertByName` stays `""`. 4. Client using the Go-parsed outbound fails the handshake on cert-name mismatch; TS-imported outbound works. ### Expected behavior Go and TS importers both apply `vcn` → `tlsSettings.verifyPeerCertByName` for TLS links (same as Hysteria already does in Go at `parseHysteria2`). ### Actual behavior `applySecurity` reads `sni` / `fp` / `alpn` / `ech` / `pcs` only and leaves the empty `verifyPeerCertByName` seeded by `buildStream`. TS `applySecurityParams` sets `tls.verifyPeerCertByName` from `vcn`. ### File pointers (main @ 0a2cd789ba11) - Generator: `internal/sub/service.go` (emits `params["vcn"]` for TLS inbounds with verifyPeerCertByName). - Go drop: `internal/util/link/outbound.go` → `applySecurity` TLS branch (no `vcn` read). Contrast: Hysteria path already maps `vcn`. - TS keep: `frontend/src/lib/xray/outbound-link-parser.ts` → `applySecurityParams` sets `tls.verifyPeerCertByName = params.get('vcn')`. ### Suggested fix size Small: one assignment in Go `applySecurity` TLS branch (`tls["verifyPeerCertByName"] = p.Get("vcn")`), plus a regression test next to existing link-parse coverage. ### 3x-ui version main (post-3.7.0)
bsakaguchi 2026-10-31 20:39:10 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

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

Confirmed — the Go share-link importer does drop vcn, and it is still dropped at the tip of main (0a2cd789). Your file pointers are accurate, and the divergence is wider than the one helper you named.

What the source says

The generator emits it. applyShareTLSParams is the shared TLS-param builder for the vless / trojan / shadowsocks links (called at internal/sub/service.go:1063, :1116, :1191):

// internal/sub/service.go:1676
if vcn, ok := verifyPeerCertByNameValue(tlsSettings); ok {
    params["vcn"] = vcn
}
if pins, ok := pinnedSha256List(tlsSettings); ok {
    params["pcs"] = strings.Join(pins, ",")
}

The Go importer reads pcs from that same pair but never vcn:

// 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")

so the "verifyPeerCertByName": "" seeded at internal/util/link/outbound.go:583 survives. applySecurity is called only from parseVless (:274) and parseTrojan (:316). The Hysteria2 branch does map it — "verifyPeerCertByName": params.Get("vcn"), at internal/util/link/outbound.go:455 — and TS does too, at frontend/src/lib/xray/outbound-link-parser.ts:399.

Two things your report did not cover

  1. vmess has the same drop, in a second place. applyVmessTLSParams writes obj["vcn"] into the vmess JSON (internal/sub/service.go:1711), but parseVmess has its own inline TLS block that only maps sni/fp/alpn:
    // internal/util/link/outbound.go:201
    if security == "tls" {
        tls := stream["tlsSettings"].(map[string]any)
        tls["serverName"] = getString(j, "sni", "")
        tls["fingerprint"] = getString(j, "fp", "")
        if alpn := getString(j, "alpn", ""); alpn != "" {
            tls["alpn"] = splitComma(alpn)
        }
    }
    
    It drops ech and pcs there as well, so a one-line fix in applySecurity alone still leaves vmess broken.
  2. A second consumer path, and it is the more damaging one. Besides the JSON subscription for external links (internal/sub/json_service.go:182 → parsedExternalOutbound), link.ParseSubscriptionBody also feeds the panel's own outbound subscriptions at internal/web/service/outbound_subscription.go:394. There the parsed outbounds become the panel's own Xray client config, so a fetched upstream link with vcn gives the local Xray an outbound that fails peer verification. (The Clash external path, internal/sub/clash_external.go:15, is unaffected — mihomo has no equivalent field and the converter never reads it.)

How it got here

7c888946 ("feat(tls,reality): port xray TLS/REALITY fields…") added vcn to the generators and to the TS parser; its file list does not include internal/util/link/ at all, so the Go importer was never updated. 5e1cb769 (#5970) later noticed the gap and fixed exactly one branch — its own commit message says "parseHysteria2 hardcoded verifyPeerCertByName to empty, ignoring the vcn param the panel emits… The TS parser handles both; make the Go parser match." — and shipped TestParse_Hysteria2VerifyPeerCertByName (internal/util/link/outbound_helpers_test.go:193). The vless/trojan and vmess branches were left behind. Nothing in the source defends the omission: TestParse_TLSSecurityMapped (internal/util/link/outbound_helpers_test.go:125) asserts serverName, fingerprint, echConfigList, pinnedPeerCertSha256 and alpn for a trojan link and simply has no vcn case.

Suggested fix: map vcn in the applySecurity TLS branch alongside the existing pcs line, and mirror it in the parseVmess TLS block at internal/util/link/outbound.go:201; TestParse_TLSSecurityMapped is the natural home for the regression assertion. Keep it to those two assignments — the gap is a missed field, not a missing layer.

Verdict: Confirmed bug
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, leaving the "verifyPeerCertByName": "" seed from buildStream (internal/util/link/outbound.go:583); parseVmess (internal/util/link/outbound.go:201-208) has the same omission for the vmess JSON form. Triggered whenever a link carrying vcn is parsed in Go — i.e. the source inbound has tlsSettings.settings.verifyPeerCertByName set. Introduced by 7c888946, which updated the generators and the TS parser but not internal/util/link/; 5e1cb769 (#5970) fixed only the Hysteria2 branch.
Already fixed: Still present on the default branch (0a2cd789, the tip as of this run); no commit or merged PR since v3.7.0 touches the TLS branch of applySecurity.
Duplicate of: None. Related: #6477 is this same report re-filed one minute later by the same author; it should be closed in favour of this one.
Evidence: internal/sub/service.go:1676-1681 (params["vcn"] + params["pcs"] emitted together); internal/sub/service.go:1711-1713 (vmess obj["vcn"]); internal/util/link/outbound.go:658-669 (applySecurity, reads pcs, not vcn); internal/util/link/outbound.go:583 ("verifyPeerCertByName": "" seed); internal/util/link/outbound.go:455 (Hysteria2 maps it); internal/util/link/outbound.go:201-208 (vmess drops it); frontend/src/lib/xray/outbound-link-parser.ts:399 (TS keeps 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 and :193; commits 7c888946, 5e1cb769.
Not determined: Whether the shadowsocks branch is affected the same way. genShadowsocksLink does call applyShareTLSParams (internal/sub/service.go:1191) and so emits vcn, but parseShadowsocks discards the entire query string at internal/util/link/outbound.go:345-347 and emits no streamSettings at all — a broader, separate gap that a vcn fix would not address, and which I did not investigate further. Reading parseShadowsocks against the TS shadowsocks parser would settle whether that is deliberate.

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

<!-- gh-comment-id:5637847597 --> @github-actions[bot] commented on GitHub (Sep 11, 2026): Confirmed — the Go share-link importer does drop `vcn`, and it is still dropped at the tip of `main` (`0a2cd789`). Your file pointers are accurate, and the divergence is wider than the one helper you named. ### What the source says The generator emits it. `applyShareTLSParams` is the shared TLS-param builder for the vless / trojan / shadowsocks links (called at `internal/sub/service.go:1063`, `:1116`, `:1191`): ```go // internal/sub/service.go:1676 if vcn, ok := verifyPeerCertByNameValue(tlsSettings); ok { params["vcn"] = vcn } if pins, ok := pinnedSha256List(tlsSettings); ok { params["pcs"] = strings.Join(pins, ",") } ``` The Go importer reads `pcs` from that same pair but never `vcn`: ```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") ``` so the `"verifyPeerCertByName": ""` seeded at `internal/util/link/outbound.go:583` survives. `applySecurity` is called only from `parseVless` (`:274`) and `parseTrojan` (`:316`). The Hysteria2 branch does map it — `"verifyPeerCertByName": params.Get("vcn"),` at `internal/util/link/outbound.go:455` — and TS does too, at `frontend/src/lib/xray/outbound-link-parser.ts:399`. ### Two things your report did not cover 1. **vmess has the same drop, in a second place.** `applyVmessTLSParams` writes `obj["vcn"]` into the vmess JSON (`internal/sub/service.go:1711`), but `parseVmess` has its own inline TLS block that only maps `sni`/`fp`/`alpn`: ```go // internal/util/link/outbound.go:201 if security == "tls" { tls := stream["tlsSettings"].(map[string]any) tls["serverName"] = getString(j, "sni", "") tls["fingerprint"] = getString(j, "fp", "") if alpn := getString(j, "alpn", ""); alpn != "" { tls["alpn"] = splitComma(alpn) } } ``` It drops `ech` and `pcs` there as well, so a one-line fix in `applySecurity` alone still leaves vmess broken. 2. **A second consumer path, and it is the more damaging one.** Besides the JSON subscription for external links (`internal/sub/json_service.go:182` → `parsedExternalOutbound`), `link.ParseSubscriptionBody` also feeds the panel's own outbound subscriptions at `internal/web/service/outbound_subscription.go:394`. There the parsed outbounds become the panel's *own* Xray client config, so a fetched upstream link with `vcn` gives the local Xray an outbound that fails peer verification. (The Clash external path, `internal/sub/clash_external.go:15`, is unaffected — mihomo has no equivalent field and the converter never reads it.) ### How it got here `7c888946` ("feat(tls,reality): port xray TLS/REALITY fields…") added `vcn` to the generators and to the TS parser; its file list does not include `internal/util/link/` at all, so the Go importer was never updated. `5e1cb769` (#5970) later noticed the gap and fixed exactly one branch — its own commit message says *"parseHysteria2 hardcoded verifyPeerCertByName to empty, ignoring the vcn param the panel emits… The TS parser handles both; make the Go parser match."* — and shipped `TestParse_Hysteria2VerifyPeerCertByName` (`internal/util/link/outbound_helpers_test.go:193`). The vless/trojan and vmess branches were left behind. Nothing in the source defends the omission: `TestParse_TLSSecurityMapped` (`internal/util/link/outbound_helpers_test.go:125`) asserts `serverName`, `fingerprint`, `echConfigList`, `pinnedPeerCertSha256` and `alpn` for a trojan link and simply has no `vcn` case. Suggested fix: map `vcn` in the `applySecurity` TLS branch alongside the existing `pcs` line, and mirror it in the `parseVmess` TLS block at `internal/util/link/outbound.go:201`; `TestParse_TLSSecurityMapped` is the natural home for the regression assertion. Keep it to those two assignments — the gap is a missed field, not a missing layer. Verdict: Confirmed bug 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, leaving the `"verifyPeerCertByName": ""` seed from `buildStream` (`internal/util/link/outbound.go:583`); `parseVmess` (`internal/util/link/outbound.go:201-208`) has the same omission for the vmess JSON form. Triggered whenever a link carrying `vcn` is parsed in Go — i.e. the source inbound has `tlsSettings.settings.verifyPeerCertByName` set. Introduced by `7c888946`, which updated the generators and the TS parser but not `internal/util/link/`; `5e1cb769` (#5970) fixed only the Hysteria2 branch. Already fixed: Still present on the default branch (`0a2cd789`, the tip as of this run); no commit or merged PR since v3.7.0 touches the TLS branch of `applySecurity`. Duplicate of: None. Related: #6477 is this same report re-filed one minute later by the same author; it should be closed in favour of this one. Evidence: `internal/sub/service.go:1676-1681` (`params["vcn"]` + `params["pcs"]` emitted together); `internal/sub/service.go:1711-1713` (vmess `obj["vcn"]`); `internal/util/link/outbound.go:658-669` (`applySecurity`, reads `pcs`, not `vcn`); `internal/util/link/outbound.go:583` (`"verifyPeerCertByName": ""` seed); `internal/util/link/outbound.go:455` (Hysteria2 maps it); `internal/util/link/outbound.go:201-208` (vmess drops it); `frontend/src/lib/xray/outbound-link-parser.ts:399` (TS keeps 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` and `:193`; commits `7c888946`, `5e1cb769`. Not determined: Whether the shadowsocks branch is affected the same way. `genShadowsocksLink` does call `applyShareTLSParams` (`internal/sub/service.go:1191`) and so emits `vcn`, but `parseShadowsocks` discards the entire query string at `internal/util/link/outbound.go:345-347` and emits no `streamSettings` at all — a broader, separate gap that a `vcn` fix would not address, and which I did not investigate further. Reading `parseShadowsocks` against the TS shadowsocks parser would settle whether that is deliberate. *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#4368
No description provided.