[GH-ISSUE #5221] [Bug]: x-ui adds mkcp-legacy finalmask to inbounds #3658

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

Originally created by @femdiya on GitHub (Jun 12, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5221

Describe the bug

Before creating an inbound, simply switching once to mKCP mode will cause any client attached to that inbound to get a mkcp-legacy finalmask:

{
  "udp": [
    {
      "settings": {
        "header": "",
        "value": ""
      },
      "type": "mkcp-legacy"
    }
  ]
}

How to reproduce the problem

  1. Open inbounds page
  2. Prepare to create an inbound
  3. Switch from RAW to mKCP
  4. Switch back from mKCP to RAW
  5. Attach client to said inbound
  6. Client export will have mkcp-legacy finalmask attached to it.

Expected behavior

x-ui shouldn't attach any unwanted strings to my client.

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.3.0

Xray-core version

26.6.1

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24.04

Which parts of the panel are affected?

Xray config generation

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

No — direct access

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @femdiya on GitHub (Jun 12, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5221 ### Describe the bug Before creating an inbound, simply switching once to mKCP mode will cause any client attached to that inbound to get a mkcp-legacy finalmask: ``` { "udp": [ { "settings": { "header": "", "value": "" }, "type": "mkcp-legacy" } ] } ``` ### How to reproduce the problem 1. Open inbounds page 2. Prepare to create an inbound 3. Switch from RAW to mKCP 4. Switch back from mKCP to RAW 5. Attach client to said inbound 6. Client export will have mkcp-legacy finalmask attached to it. ### Expected behavior x-ui shouldn't attach any unwanted strings to my client. ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.3.0 ### Xray-core version 26.6.1 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24.04 ### Which parts of the panel are affected? Xray config generation ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? No — direct access ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:34:02 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 12, 2026):

The bug is confirmed in the source and is reproducible as described. The root cause is in frontend/src/pages/inbounds/form/InboundFormModal.tsx, in the onNetworkChange function (around line 739).

What happens

When the user switches the network selector to kcp (mKCP), onNetworkChange auto-seeds streamSettings.finalmask.udp with a {type: "mkcp-legacy", settings: {header: "", value: ""}} entry as a sensible default for mKCP traffic. This is intentional. However, when the user subsequently switches the network back to any other transport (e.g., tcp/RAW), the function removes the kcpSettings key from the form state but does not remove the auto-seeded finalmask entry. The finalmask block is left behind.

Why it survives to the wire payload and client exports

Two downstream guards both fail to remove it:

  1. dropLegacyOptionalEmpties in frontend/src/lib/xray/inbound-form-adapter.ts (line ~289) prunes the entire finalmask block only when all of tcp, udp, and quicParams are empty. Because the stale udp array still has one entry, hasUdp is true and the block is kept.

  2. hasShareableFinalMaskValue in frontend/src/lib/xray/inbound-link.ts (line ~101) returns true for the entry because the type field ("mkcp-legacy") is a non-empty string. So the fm query parameter is serialized into every client share link.

The result is that the inbound is saved to the database with finalmask.udp = [{type: "mkcp-legacy", settings: {header: "", value: ""}}] inside streamSettings regardless of the active transport, and every client export carries the orphaned mask.

Workaround until a fix ships

After saving the affected inbound, open the Advanced → Stream editor in the panel, locate the finalmask key in the JSON, and either delete the entire finalmask block or clear its udp array:

"finalmask": {
  "tcp": [],
  "udp": []
}

Save the inbound again. Clients generated after that will no longer carry the stale mkcp-legacy mask.

Expected fix

The onNetworkChange handler should clear (or omit) the finalmask.udp mkcp-legacy entry it auto-seeded whenever the network changes away from kcp. The simplest approach is to strip any mkcp-legacy entries from finalmask.udp in the else-branch of the if (next === 'kcp') block.

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

<!-- gh-comment-id:4691539222 --> @github-actions[bot] commented on GitHub (Jun 12, 2026): The bug is confirmed in the source and is reproducible as described. The root cause is in `frontend/src/pages/inbounds/form/InboundFormModal.tsx`, in the `onNetworkChange` function (around line 739). **What happens** When the user switches the network selector to `kcp` (mKCP), `onNetworkChange` auto-seeds `streamSettings.finalmask.udp` with a `{type: "mkcp-legacy", settings: {header: "", value: ""}}` entry as a sensible default for mKCP traffic. This is intentional. However, when the user subsequently switches the network back to any other transport (e.g., `tcp`/RAW), the function removes the `kcpSettings` key from the form state but does **not** remove the auto-seeded `finalmask` entry. The finalmask block is left behind. **Why it survives to the wire payload and client exports** Two downstream guards both fail to remove it: 1. `dropLegacyOptionalEmpties` in `frontend/src/lib/xray/inbound-form-adapter.ts` (line ~289) prunes the entire `finalmask` block only when **all** of `tcp`, `udp`, and `quicParams` are empty. Because the stale `udp` array still has one entry, `hasUdp` is `true` and the block is kept. 2. `hasShareableFinalMaskValue` in `frontend/src/lib/xray/inbound-link.ts` (line ~101) returns `true` for the entry because the `type` field (`"mkcp-legacy"`) is a non-empty string. So the `fm` query parameter is serialized into every client share link. The result is that the inbound is saved to the database with `finalmask.udp = [{type: "mkcp-legacy", settings: {header: "", value: ""}}]` inside `streamSettings` regardless of the active transport, and every client export carries the orphaned mask. **Workaround until a fix ships** After saving the affected inbound, open the **Advanced → Stream** editor in the panel, locate the `finalmask` key in the JSON, and either delete the entire `finalmask` block or clear its `udp` array: ```json "finalmask": { "tcp": [], "udp": [] } ``` Save the inbound again. Clients generated after that will no longer carry the stale `mkcp-legacy` mask. **Expected fix** The `onNetworkChange` handler should clear (or omit) the `finalmask.udp` `mkcp-legacy` entry it auto-seeded whenever the network changes away from `kcp`. The simplest approach is to strip any `mkcp-legacy` entries from `finalmask.udp` in the else-branch of the `if (next === 'kcp')` block. *This reply was generated automatically; a maintainer may follow up.*
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#3658
No description provided.