[GH-ISSUE #6476] [Bug]: Share-link import drops mKCP seed and headerType #4369

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/6476

Describe the bug

Share links generated for mKCP inbounds include type=kcp, headerType, and seed (via applyKcpShareParams), but both importers ignore those query params. Re-importing the link yields an outbound with the canned kcpSettings defaults (no seed, no header), so xray-core silently drops every packet from that outbound.

Affected paths (same gap in both twins):

  • Go: internal/util/link/outbound.go — applyTransport switch covers ws / grpc / httpupgrade / xhttp / tcp only; no kcp branch
  • TS: frontend/src/lib/xray/outbound-link-parser.ts — applyTransportParams has the same set

buildStream does seed a default kcpSettings block when network=kcp, but nothing copies headerType / seed / mtu / tti from the query into it.

Generator side (what the link contains): internal/sub/service.go → applyKcpShareParams → kcpShareFields.applyToParams writes headerType and seed (and related fields).

How to reproduce the problem

  1. Create a VLESS (or Trojan) inbound with network kcp, a non-empty seed, and header type wechat-video (or any non-none header).
  2. Copy a client share link from the panel (or from /panel/api/inbounds/allLinks). Confirm the query contains type=kcp&headerType=wechat-video&seed=....
  3. Import that link as an outbound (panel outbound import, or any path that uses internal/util/link / outbound-link-parser).
  4. Inspect the imported outbound's streamSettings.kcpSettings: seed is empty / absent and header is missing or none.

Expected behavior

Importing an mKCP share link restores the same seed, headerType (and other emitted kcp fields) that the panel put on the link, so the outbound can talk to the inbound that emitted it.

Actual behavior

Import keeps only the canned kcpSettings defaults from buildStream. The connection fails silently (no useful error; packets discarded).

3x-ui version

main (checked against current default branch)

Suggested fix size

Small: add a kcp branch to applyTransport / applyTransportParams in both Go and TS importers (mirror what applyKcpShareParams emits).

Adjacent to the SS TLS import work in #6094 / #6467 (same helpers). Not a duplicate of #6094.

Originally created by @mrchatam on GitHub (Sep 11, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6476 ### Describe the bug Share links generated for mKCP inbounds include `type=kcp`, `headerType`, and `seed` (via `applyKcpShareParams`), but both importers ignore those query params. Re-importing the link yields an outbound with the canned `kcpSettings` defaults (no seed, no header), so xray-core silently drops every packet from that outbound. Affected paths (same gap in both twins): - Go: `internal/util/link/outbound.go` — `applyTransport` switch covers `ws` / `grpc` / `httpupgrade` / `xhttp` / `tcp` only; no `kcp` branch - TS: `frontend/src/lib/xray/outbound-link-parser.ts` — `applyTransportParams` has the same set `buildStream` *does* seed a default `kcpSettings` block when `network=kcp`, but nothing copies `headerType` / `seed` / `mtu` / `tti` from the query into it. Generator side (what the link contains): `internal/sub/service.go` → `applyKcpShareParams` → `kcpShareFields.applyToParams` writes `headerType` and `seed` (and related fields). ### How to reproduce the problem 1. Create a VLESS (or Trojan) inbound with network `kcp`, a non-empty `seed`, and header type `wechat-video` (or any non-`none` header). 2. Copy a client share link from the panel (or from `/panel/api/inbounds/allLinks`). Confirm the query contains `type=kcp&headerType=wechat-video&seed=...`. 3. Import that link as an outbound (panel outbound import, or any path that uses `internal/util/link` / `outbound-link-parser`). 4. Inspect the imported outbound's `streamSettings.kcpSettings`: seed is empty / absent and header is missing or `none`. ### Expected behavior Importing an mKCP share link restores the same `seed`, `headerType` (and other emitted kcp fields) that the panel put on the link, so the outbound can talk to the inbound that emitted it. ### Actual behavior Import keeps only the canned `kcpSettings` defaults from `buildStream`. The connection fails silently (no useful error; packets discarded). ### 3x-ui version main (checked against current default branch) ### Suggested fix size Small: add a `kcp` branch to `applyTransport` / `applyTransportParams` in both Go and TS importers (mirror what `applyKcpShareParams` emits). ### Related Adjacent to the SS TLS import work in #6094 / #6467 (same helpers). Not a duplicate of #6094.
Author
Owner

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

This is a duplicate of #6473 — same two functions, same proposed fix, opened the same day — so I'm closing this one and leaving #6473 as the tracking issue. Worth reading before that one gets fixed, though: the code gap you describe is real, but the consequence isn't, and that changes what the fix should be.

The gap is real

Neither importer has a kcp branch:

internal/util/link/outbound.go:610              switch net { case "ws" / "grpc" / "httpupgrade" / "xhttp" / "tcp" }
frontend/src/lib/xray/outbound-link-parser.ts:197   the same five cases

But seed / headerType no longer carry mKCP obfuscation

Commit 32f96298 ("feat(finalmask): sync transport with upstream Xray core changes") consolidated the legacy mKCP header masks into a single FinalMask mkcp-legacy UDP mask, "matching the updated Xray-core wire format". The panel's mKCP model has no seed and no header left:

// frontend/src/schemas/protocols/stream/kcp.ts:6-13
export const KcpStreamSettingsSchema = z.object({
  mtu, tti, uplinkCapacity, downlinkCapacity, cwndMultiplier, maxSendingWindow
});

The inbound form (frontend/src/pages/inbounds/form/transport/kcp.tsx:10-44) and the outbound form (frontend/src/pages/xray/outbounds/transport/kcp.tsx:10-44) both show exactly those six fields. docs/content/docs/en/config/transports.mdx:53-57 says it outright:

the mkcp-legacy mask reproduces the classic header obfuscation that older Xray stored in kcpSettings.header/seed (those fields no longer exist here).

So step 1 of your repro — an inbound with "a non-empty seed and header type wechat-video" — is not reachable on current main. You set Header: WeChat Video + Value: on an mkcp-legacy FinalMask UDP mask instead (FinalMaskForm.tsx:938-957), which InboundFormModal.tsx:857-869 seeds automatically when you switch a transport to mKCP.

And that mask does round-trip on import

The same link carries fm=<finalmask json> (internal/sub/service.go:1058 and :2636-2639; TS inbound-link.ts:326), and both importers restore it right after applyTransport:

// internal/util/link/outbound.go:273-275 (vless), :315-317 (trojan)
applyTransport(stream, params)
applySecurity(stream, params)
applyFinalMask(stream, params)   // :681-688 → stream["finalmask"] = parsed
// frontend/src/lib/xray/outbound-link-parser.ts:505-507 (vless), :532-534 (trojan)
applyTransportParams(stream, params);
applySecurityParams(stream, params);
applyFinalMaskParam(stream, params);   // :242-253

mkcp-legacy is in validFinalMaskUDPTypes (internal/sub/service.go:2486), so the mask survives marshalFinalMask and lands back on the imported outbound.

The headerType= / seed= params the Go generator writes are legacy-compat exports for third-party clients, derived from that same mask: extractKcpShareFields maps header:"wechat" → headerType=wechat-video and header:"" → seed=<value> (internal/sub/service.go:2559-2578, pinned by TestExtractKcpShareFields_FinalMaskLegacyHeader and TestExtractKcpShareFields_FinalMaskLegacySeed). Copying them back into kcpSettings on import would write fields the current model no longer has, on top of what fm already restored.

What is genuinely dropped: mtu and tti

Both generators emit them — kcpShareFields.applyToParams (internal/sub/service.go:2526-2527, via setIntParam, only when > 0) and inbound-link.ts:417-418 / :522-523 — and both importers hardcode the defaults instead:

// internal/util/link/outbound.go:558-562
case "kcp":
	stream["kcpSettings"] = map[string]any{
		"mtu": 1350, "tti": 20, "uplinkCapacity": 5, "downlinkCapacity": 20,
		"cwndMultiplier": 1, "maxSendingWindow": 2097152,
	}

An inbound at mtu=1200, tti=50 therefore imports as 1350/20. That is the part of #6473 that is a real defect. I could not determine from this repo whether a mismatched mKCP mtu/tti actually breaks a connection or only changes pacing — that behaviour lives in xray-core, not here — so the "packets discarded, silent failure" description is not something I can confirm.

Verdict: Duplicate
Severity: Low
Confidence: High
Root cause: applyTransport (internal/util/link/outbound.go:606-656) and applyTransportParams (frontend/src/lib/xray/outbound-link-parser.ts:193-237) have no kcp case, so the mtu/tti query params are discarded and buildStream's hardcoded mtu:1350, tti:20 (outbound.go:559-562, outbound-link-parser.ts:141-148) stand. The headerType/seed half of the report has no root cause: those params are legacy exports and the live obfuscation round-trips via fm.
Already fixed: Still present on the default branch (0a2cd789) for mtu/tti.
Duplicate of: #6473 — same missing kcp branch in applyTransport / applyTransportParams, same generator (applyKcpShareParams), same proposed fix.
Evidence: internal/util/link/outbound.go:610 and frontend/src/lib/xray/outbound-link-parser.ts:197 (no kcp case); outbound.go:275/:681-688 and outbound-link-parser.ts:507/:242-253 (fm restores finalmask after applyTransport); frontend/src/schemas/protocols/stream/kcp.ts:6-13 (no seed/header in the model); docs/content/docs/en/config/transports.mdx:53-57 ("those fields no longer exist here"); commit 32f96298; internal/sub/service.go:2559-2578 + TestExtractKcpShareFields_FinalMaskLegacyHeader (service_test.go:966-984).
Not determined: Whether a link carrying headerType/seed with no fm — a third-party generator, or an inbound row still holding the pre-32f96298 kcpSettings.header/seed shape, which nothing in internal/database/db.go migrates — describes a working inbound at all. That depends on whether the pinned github.com/xtls/xray-core v1.260327.1-0.20260908222543-52a412d9e2f5 (go.mod:28) still honours kcpSettings.header/seed; I cannot inspect that module from this checkout. Reading its transport/internet/kcp config would settle it.

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

<!-- gh-comment-id:5637887920 --> @github-actions[bot] commented on GitHub (Sep 11, 2026): This is a duplicate of #6473 — same two functions, same proposed fix, opened the same day — so I'm closing this one and leaving #6473 as the tracking issue. Worth reading before that one gets fixed, though: the code gap you describe is real, but the consequence isn't, and that changes what the fix should be. ### The gap is real Neither importer has a `kcp` branch: ``` internal/util/link/outbound.go:610 switch net { case "ws" / "grpc" / "httpupgrade" / "xhttp" / "tcp" } frontend/src/lib/xray/outbound-link-parser.ts:197 the same five cases ``` ### But `seed` / `headerType` no longer carry mKCP obfuscation Commit `32f96298` ("feat(finalmask): sync transport with upstream Xray core changes") consolidated the legacy mKCP header masks into a single FinalMask `mkcp-legacy` UDP mask, "matching the updated Xray-core wire format". The panel's mKCP model has no `seed` and no `header` left: ```ts // frontend/src/schemas/protocols/stream/kcp.ts:6-13 export const KcpStreamSettingsSchema = z.object({ mtu, tti, uplinkCapacity, downlinkCapacity, cwndMultiplier, maxSendingWindow }); ``` The inbound form (`frontend/src/pages/inbounds/form/transport/kcp.tsx:10-44`) and the outbound form (`frontend/src/pages/xray/outbounds/transport/kcp.tsx:10-44`) both show exactly those six fields. `docs/content/docs/en/config/transports.mdx:53-57` says it outright: > the `mkcp-legacy` mask reproduces the classic header obfuscation that older Xray stored in `kcpSettings.header`/`seed` (those fields no longer exist here). So step 1 of your repro — an inbound with "a non-empty `seed` and header type `wechat-video`" — is not reachable on current `main`. You set `Header: WeChat Video` + `Value:` on an `mkcp-legacy` FinalMask UDP mask instead (`FinalMaskForm.tsx:938-957`), which `InboundFormModal.tsx:857-869` seeds automatically when you switch a transport to mKCP. ### And that mask *does* round-trip on import The same link carries `fm=<finalmask json>` (`internal/sub/service.go:1058` and `:2636-2639`; TS `inbound-link.ts:326`), and both importers restore it right after `applyTransport`: ```go // internal/util/link/outbound.go:273-275 (vless), :315-317 (trojan) applyTransport(stream, params) applySecurity(stream, params) applyFinalMask(stream, params) // :681-688 → stream["finalmask"] = parsed ``` ```ts // frontend/src/lib/xray/outbound-link-parser.ts:505-507 (vless), :532-534 (trojan) applyTransportParams(stream, params); applySecurityParams(stream, params); applyFinalMaskParam(stream, params); // :242-253 ``` `mkcp-legacy` is in `validFinalMaskUDPTypes` (`internal/sub/service.go:2486`), so the mask survives `marshalFinalMask` and lands back on the imported outbound. The `headerType=` / `seed=` params the Go generator writes are legacy-compat exports for third-party clients, *derived from* that same mask: `extractKcpShareFields` maps `header:"wechat"` → `headerType=wechat-video` and `header:""` → `seed=<value>` (`internal/sub/service.go:2559-2578`, pinned by `TestExtractKcpShareFields_FinalMaskLegacyHeader` and `TestExtractKcpShareFields_FinalMaskLegacySeed`). Copying them back into `kcpSettings` on import would write fields the current model no longer has, on top of what `fm` already restored. ### What is genuinely dropped: `mtu` and `tti` Both generators emit them — `kcpShareFields.applyToParams` (`internal/sub/service.go:2526-2527`, via `setIntParam`, only when `> 0`) and `inbound-link.ts:417-418` / `:522-523` — and both importers hardcode the defaults instead: ```go // internal/util/link/outbound.go:558-562 case "kcp": stream["kcpSettings"] = map[string]any{ "mtu": 1350, "tti": 20, "uplinkCapacity": 5, "downlinkCapacity": 20, "cwndMultiplier": 1, "maxSendingWindow": 2097152, } ``` An inbound at `mtu=1200, tti=50` therefore imports as `1350/20`. That is the part of #6473 that is a real defect. I could not determine from this repo whether a mismatched mKCP `mtu`/`tti` actually breaks a connection or only changes pacing — that behaviour lives in xray-core, not here — so the "packets discarded, silent failure" description is not something I can confirm. Verdict: Duplicate Severity: Low Confidence: High Root cause: `applyTransport` (`internal/util/link/outbound.go:606-656`) and `applyTransportParams` (`frontend/src/lib/xray/outbound-link-parser.ts:193-237`) have no `kcp` case, so the `mtu`/`tti` query params are discarded and `buildStream`'s hardcoded `mtu:1350, tti:20` (`outbound.go:559-562`, `outbound-link-parser.ts:141-148`) stand. The `headerType`/`seed` half of the report has no root cause: those params are legacy exports and the live obfuscation round-trips via `fm`. Already fixed: Still present on the default branch (`0a2cd789`) for `mtu`/`tti`. Duplicate of: #6473 — same missing `kcp` branch in `applyTransport` / `applyTransportParams`, same generator (`applyKcpShareParams`), same proposed fix. Evidence: `internal/util/link/outbound.go:610` and `frontend/src/lib/xray/outbound-link-parser.ts:197` (no `kcp` case); `outbound.go:275`/`:681-688` and `outbound-link-parser.ts:507`/`:242-253` (`fm` restores `finalmask` after `applyTransport`); `frontend/src/schemas/protocols/stream/kcp.ts:6-13` (no `seed`/`header` in the model); `docs/content/docs/en/config/transports.mdx:53-57` ("those fields no longer exist here"); commit `32f96298`; `internal/sub/service.go:2559-2578` + `TestExtractKcpShareFields_FinalMaskLegacyHeader` (`service_test.go:966-984`). Not determined: Whether a link carrying `headerType`/`seed` with **no** `fm` — a third-party generator, or an inbound row still holding the pre-`32f96298` `kcpSettings.header`/`seed` shape, which nothing in `internal/database/db.go` migrates — describes a working inbound at all. That depends on whether the pinned `github.com/xtls/xray-core v1.260327.1-0.20260908222543-52a412d9e2f5` (`go.mod:28`) still honours `kcpSettings.header`/`seed`; I cannot inspect that module from this checkout. Reading its `transport/internet/kcp` config would settle it. *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#4369
No description provided.