[PR #6522] [MERGED] fix(panel): read an outbound protocol id the way the core does #6329

Closed
opened 2026-11-02 04:07:59 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6522
Author: @BlindMaster24
Created: 9/14/2026
Status: ✅ Merged
Merged: 9/14/2026
Merged by: @MHSanaei

Base: main ← Head: fix/outbound-protocol-case


📝 Commits (3)

  • dd7963c fix(panel): read an outbound protocol id the way the core does
  • f1e3a99 fix(panel): never leave the direct tag on two outbounds
  • f77f4c9 fix(panel): disable the freedom controls when direct is held elsewhere

📊 Changes

6 files changed (+150 additions, -21 deletions)

View changed files

📝 frontend/src/lib/xray/outbound-form-adapter.ts (+3 -1)
📝 frontend/src/pages/xray/basics/BasicsTab.tsx (+14 -10)
📝 frontend/src/pages/xray/basics/helpers.ts (+28 -10)
📝 frontend/src/test/basics-freedom-strategy.test.ts (+35 -0)
➕ frontend/src/test/basics-tab-direct-tag.test.tsx (+44 -0)
📝 frontend/src/test/outbound-form-adapter.test.ts (+26 -0)

📄 Description

Summary

xray-core lowercases a protocol id before it looks the handler up, so a template that spells the direct outbound Freedom is that outbound — but the panel matched the id exactly. The outbound editor rendered it as an empty vless server, and the Basics tab could not find it and appended a second outbound tagged direct.

Why

infra/conf/loader.go in the pinned core:

func (v *JSONConfigLoader) LoadWithID(raw []byte, id string) (interface{}, error) {
	id = strings.ToLower(id)

infra/conf/xray.go:329 hands it c.Protocol for every outbound, so the spelling never changes which handler runs. Two panel paths disagreed:

  1. The Basics tab could append a duplicate tag and stop xray from starting. setDirectFreedomStrategy and the happy-eyeballs setter both look the direct outbound up with o?.protocol === 'freedom' && o?.tag === 'direct' and, on a miss, push({ protocol: 'freedom', tag: 'direct', settings: {} }). On a template spelled Freedom the lookup always missed, so changing the Freedom Protocol Strategy select (or the happy-eyeballs toggle) added a second direct outbound. The core rejects that outright — app/proxyman/outbound/outbound.go:115:

    if _, found := m.taggedHandler[tag]; found {
        return errors.New("existing tag found: " + tag)
    }
    

    So the panel's own settings page could leave the box unable to start xray, and every routing rule pointing at direct would then resolve to the wrong handler.

  2. The outbound editor rendered the same outbound as an empty vless server. rawOutboundToFormValues switched on the raw string and fell through default: to the vless branch, so the outbounds list showed a vless server with no address; the required-address rule then refused to save it, and saving from the JSON tab would have rewritten the outbound as vless.

User story: a user pastes their config into Xray Settings → JSON (or imports one) with "protocol": "Freedom" for the direct outbound — the core accepts it and keeps running, so nothing warns. Then they open Xray → Basics and change Freedom Protocol Strategy, and the panel saves a duplicate direct. The next restart fails with existing tag found: direct.

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?

  • frontend/src/test/basics-freedom-strategy.test.ts — a template whose direct outbound is Freedom with sockopt.domainStrategy: UseIPv6 must report UseIPv6 and must still hold one outbound after setDirectFreedomStrategy(t, 'UseIPv4'), with the value landing on that outbound. Reverting the predicate to the exact match reddens exactly this test (verified by mutating it back).
  • frontend/src/test/outbound-form-adapter.test.ts — "Freedom" parses as freedom with its settings intact and saves back as the canonical id, and "VLESS" keeps its flat vless settings. Removing the normalisation reddens this test only (1 failed | 34 passed).
  • npm run typecheck, npm run lint and oxfmt --check pass on the touched files.

Honest note: the local unit suite is 1155 passed, 1 failed, and the failure is src/test/input-number-guard.test.ts, which is unrelated to this change — it also fails with my files stashed, so it is a local-environment difference in the oxlint CLI, not a regression here.

Screenshots / recordings

N/A — the change is how an id is compared; the visible difference needs a config spelled Freedom.

Breaking changes

None. Nothing is rewritten on load; the editor simply reads the id the way the core does, and saving writes the canonical lowercase id the core would have used anyway.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally. (no Go change in this PR)
  • For frontend changes: npm run lint and npm run typecheck pass, and the Vite build succeeds (npx vite build — the npm run build wrapper also runs gen:api, which this PR does not touch).
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • 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/6522 **Author:** [@BlindMaster24](https://github.com/BlindMaster24) **Created:** 9/14/2026 **Status:** ✅ Merged **Merged:** 9/14/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/outbound-protocol-case` --- ### 📝 Commits (3) - [`dd7963c`](https://github.com/MHSanaei/3x-ui/commit/dd7963ce8b16c97a801cdf88c2067ab38c3e354f) fix(panel): read an outbound protocol id the way the core does - [`f1e3a99`](https://github.com/MHSanaei/3x-ui/commit/f1e3a99e983fef667df0efc2bbabfda0ce3a7038) fix(panel): never leave the direct tag on two outbounds - [`f77f4c9`](https://github.com/MHSanaei/3x-ui/commit/f77f4c9297d1308c87b42cb8799850c56a800f02) fix(panel): disable the freedom controls when direct is held elsewhere ### 📊 Changes **6 files changed** (+150 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/lib/xray/outbound-form-adapter.ts` (+3 -1) 📝 `frontend/src/pages/xray/basics/BasicsTab.tsx` (+14 -10) 📝 `frontend/src/pages/xray/basics/helpers.ts` (+28 -10) 📝 `frontend/src/test/basics-freedom-strategy.test.ts` (+35 -0) ➕ `frontend/src/test/basics-tab-direct-tag.test.tsx` (+44 -0) 📝 `frontend/src/test/outbound-form-adapter.test.ts` (+26 -0) </details> ### 📄 Description ## Summary xray-core lowercases a protocol id before it looks the handler up, so a template that spells the direct outbound `Freedom` is that outbound — but the panel matched the id exactly. The outbound editor rendered it as an empty vless server, and the Basics tab could not find it and appended a **second** outbound tagged `direct`. ## Why `infra/conf/loader.go` in the pinned core: ```go func (v *JSONConfigLoader) LoadWithID(raw []byte, id string) (interface{}, error) { id = strings.ToLower(id) ``` `infra/conf/xray.go:329` hands it `c.Protocol` for every outbound, so the spelling never changes which handler runs. Two panel paths disagreed: 1. **The Basics tab could append a duplicate tag and stop xray from starting.** `setDirectFreedomStrategy` and the happy-eyeballs setter both look the direct outbound up with `o?.protocol === 'freedom' && o?.tag === 'direct'` and, on a miss, `push({ protocol: 'freedom', tag: 'direct', settings: {} })`. On a template spelled `Freedom` the lookup always missed, so changing the Freedom Protocol Strategy select (or the happy-eyeballs toggle) added a second `direct` outbound. The core rejects that outright — `app/proxyman/outbound/outbound.go:115`: ```go if _, found := m.taggedHandler[tag]; found { return errors.New("existing tag found: " + tag) } ``` So the panel's own settings page could leave the box unable to start xray, and every routing rule pointing at `direct` would then resolve to the wrong handler. 2. **The outbound editor rendered the same outbound as an empty vless server.** `rawOutboundToFormValues` switched on the raw string and fell through `default:` to the vless branch, so the outbounds list showed a vless server with no address; the required-address rule then refused to save it, and saving from the JSON tab would have rewritten the outbound as vless. User story: a user pastes their config into **Xray Settings → JSON** (or imports one) with `"protocol": "Freedom"` for the direct outbound — the core accepts it and keeps running, so nothing warns. Then they open **Xray → Basics** and change *Freedom Protocol Strategy*, and the panel saves a duplicate `direct`. The next restart fails with `existing tag found: direct`. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [x] 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? - `frontend/src/test/basics-freedom-strategy.test.ts` — a template whose direct outbound is `Freedom` with `sockopt.domainStrategy: UseIPv6` must report `UseIPv6` and must still hold **one** outbound after `setDirectFreedomStrategy(t, 'UseIPv4')`, with the value landing on that outbound. Reverting the predicate to the exact match reddens exactly this test (verified by mutating it back). - `frontend/src/test/outbound-form-adapter.test.ts` — `"Freedom"` parses as freedom with its settings intact and saves back as the canonical id, and `"VLESS"` keeps its flat vless settings. Removing the normalisation reddens this test only (`1 failed | 34 passed`). - `npm run typecheck`, `npm run lint` and `oxfmt --check` pass on the touched files. Honest note: the local `unit` suite is `1155 passed, 1 failed`, and the failure is `src/test/input-number-guard.test.ts`, which is unrelated to this change — it also fails with my files stashed, so it is a local-environment difference in the oxlint CLI, not a regression here. ## Screenshots / recordings N/A — the change is how an id is compared; the visible difference needs a config spelled `Freedom`. ## Breaking changes None. Nothing is rewritten on load; the editor simply reads the id the way the core does, and saving writes the canonical lowercase id the core would have used anyway. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [ ] `go build ./...` and the test suite pass locally. (no Go change in this PR) - [x] For frontend changes: `npm run lint` and `npm run typecheck` pass, and the Vite build succeeds (`npx vite build` — the `npm run build` wrapper also runs `gen:api`, which this PR does not touch). - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. - [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:59 +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#6329
No description provided.