[PR #6530] [MERGED] fix(xray): read the last two inboundTag protocol ids like the core #6336

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

📋 Pull Request Information

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

Base: main ← Head: fix/protocol-id-readers-red-first


📝 Commits (1)

  • 71b49e4 fix(xray): read the last two inboundTag protocol ids like the core

📊 Changes

4 files changed (+102 additions, -3 deletions)

View changed files

📝 internal/web/service/outbound/outbound.go (+1 -1)
📝 internal/web/service/outbound/probe_protocol_case_test.go (+31 -0)
📝 internal/web/service/xray_setting_routing_sync.go (+3 -2)
📝 internal/web/service/xray_setting_routing_sync_test.go (+67 -0)

📄 Description

Summary

Two Go readers identify an outbound by comparing its protocol id exactly, where the core lowercases that id before resolving it. Both now compare case-insensitively.

Why

An outbound's protocol id is not case-sensitive. The pinned core normalizes it — infra/conf/loader.go, LoadWithID: id = strings.ToLower(id) — so an outbound written "Loopback" is the same outbound as "loopback" and gets the same proxy/loopback handler. Two places in the panel disagreed with that, and both are reachable from the config template an operator edits.

1. A renamed or deleted inbound leaves a stale inboundTag on the loopback outbound

replaceInboundTagInOutbounds and removeInboundTagFromOutbounds (internal/web/service/xray_setting_routing_sync.go) both open with if proto != "loopback" { continue }. A loopback outbound spelled "Loopback" is skipped by both.

User story — the panel's own workflow:

  1. An operator has an inbound vless-reality and a loopback outbound whose settings.inboundTag points at it.
  2. They rename that inbound in the panel to vless-main (or delete it).
  3. The panel propagates the rename/removal into routing rules and loopback outbounds, so no rule is left pointing at a tag that no longer exists.
  4. With the old comparison, the loopback outbound is not in that set. Its settings.inboundTag still reads vless-reality.

What breaks downstream is quiet rather than loud. infra/conf/loopback.go:15 copies inboundTag into the generated config and proxy/loopback/loopback.go:43 uses it as the inbound identity for traffic that returns through that outbound. So the config still loads — but every routing rule written against vless-main stops matching traffic that comes back through the loopback outbound, because that traffic is announced under a tag that no longer exists. The operator sees a rule that looks correct and does not fire.

2. The probe lane's "nothing to test here" gate reports a different message for the same outbound

testOutboundTCP (internal/web/service/outbound/outbound.go:160) rejected protocol == "blackhole" || protocol == "freedom" exactly. A "Freedom" outbound fell through to the generic endpoint check, so the operator got No testable endpoint where the canonical spelling gets Outbound has no testable endpoint — two spellings of the same outbound taking different paths to the same rejection. Both reject, so this one is message precision, not a wrong result; it is fixed here because it is the same comparison and the same file family as the rest of this series.

This is the last of the readers found by auditing every place the panel reads a protocol id against the core's normalization. The panel now reads the id the way the core does in all of: the outbound test tier and endpoint extractor (#6526), the Outbounds row's testability gate and Address column (#6527, #6528), and these two.

Not changed, deliberately

server.go's GetDefaultLogOutboundTags has the same class of exact switch obMap["protocol"], but it scans the embedded config.json (//go:embed in setting.go:35), whose protocols are canonical by construction — an operator cannot put "Freedom" there. No test can distinguish a case-insensitive read from an exact one on that input, so it is left alone rather than patched without evidence. internal/sub's clash_external.go and json_service.go are canonical by construction too: they read the map built by parseExternalLink → link.ParseLink, which assigns the literals "vmess", "vless", "trojan", "shadowsocks", "hysteria", "wireguard".

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?

Both fixes are red-first — the test was written and watched to fail against the current code before the fix was applied, and both were re-run with the fix reverted to confirm the red is real and not incidental.

Test 1 — TestReplaceInboundTagInOutbounds_ReadsTheProtocolIDLikeTheCore / TestRemoveInboundTagFromOutbounds_ReadsTheProtocolIDLikeTheCore (internal/web/service/xray_setting_routing_sync_test.go, table-driven, no DB):

case with the old exact comparison with the fix
"loopback" rewritten rewritten
"Loopback" changed = false, tag stays old-tag changed = true, tag is new-tag
"LOOPBACK" changed = false, tag stays old-tag changed = true, tag is new-tag
"vmess" (control) untouched untouched

The removal case asserts the same three spellings clear inboundTag and that "vmess" keeps it (want the key gone vs the retained value).

Test 2 — TestTestOutboundsRejectsUntestableIDsInAnyCase (internal/web/service/outbound/probe_protocol_case_test.go), driving TestOutbounds with a batch payload over the real code path:

"Freedom"   error = "No testable endpoint", want "Outbound has no testable endpoint"
"FREEDOM"   error = "No testable endpoint", want "Outbound has no testable endpoint"
"Blackhole" error = "No testable endpoint", want "Outbound has no testable endpoint"
"freedom" / "blackhole"  (controls)  pass both before and after

Reproduce the red locally: git stash the two non-test files, run the four tests, and the case variants fail with exactly the messages above; restore and they pass.

Local gate. gofmt -l clean on all four files, go vet clean, go build ./... clean, go test ./internal/web/service/outbound/ ok, and the four new tests green. This machine has no C compiler, so the DB-backed tests in internal/web/service and the CGo build itself are CI's (the panel package's DB tests cannot run locally at all — that is environmental, not this change: it fails identically on unmodified main).

Screenshots / recordings

N/A — backend and config-generation only, no UI change.

Breaking changes

None. Both comparisons only widen which outbounds the panel recognizes as loopback outbounds and which ids the probe gate rejects; the canonical spellings behave exactly as before, which the control cases in both tables pin.

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.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • 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.

go build ./... passes here; the full go test ./... needs a C compiler for the SQLite driver, which CI has and this machine does not — same caveat as my previous PRs.


🔄 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/6530 **Author:** [@BlindMaster24](https://github.com/BlindMaster24) **Created:** 9/14/2026 **Status:** ✅ Merged **Merged:** 9/14/2026 **Merged by:** [@BlindMaster24](https://github.com/BlindMaster24) **Base:** `main` ← **Head:** `fix/protocol-id-readers-red-first` --- ### 📝 Commits (1) - [`71b49e4`](https://github.com/MHSanaei/3x-ui/commit/71b49e482e42d45eb056d8634d64b4bbe2d08a9c) fix(xray): read the last two inboundTag protocol ids like the core ### 📊 Changes **4 files changed** (+102 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/outbound/outbound.go` (+1 -1) 📝 `internal/web/service/outbound/probe_protocol_case_test.go` (+31 -0) 📝 `internal/web/service/xray_setting_routing_sync.go` (+3 -2) 📝 `internal/web/service/xray_setting_routing_sync_test.go` (+67 -0) </details> ### 📄 Description ## Summary Two Go readers identify an outbound by comparing its `protocol` id exactly, where the core lowercases that id before resolving it. Both now compare case-insensitively. ## Why An outbound's protocol id is not case-sensitive. The pinned core normalizes it — `infra/conf/loader.go`, `LoadWithID`: `id = strings.ToLower(id)` — so an outbound written `"Loopback"` is the *same* outbound as `"loopback"` and gets the same `proxy/loopback` handler. Two places in the panel disagreed with that, and both are reachable from the config template an operator edits. ### 1. A renamed or deleted inbound leaves a stale `inboundTag` on the loopback outbound `replaceInboundTagInOutbounds` and `removeInboundTagFromOutbounds` (`internal/web/service/xray_setting_routing_sync.go`) both open with `if proto != "loopback" { continue }`. A loopback outbound spelled `"Loopback"` is skipped by both. User story — the panel's own workflow: 1. An operator has an inbound `vless-reality` and a loopback outbound whose `settings.inboundTag` points at it. 2. They rename that inbound in the panel to `vless-main` (or delete it). 3. The panel propagates the rename/removal into routing rules and loopback outbounds, so no rule is left pointing at a tag that no longer exists. 4. With the old comparison, the loopback outbound is not in that set. Its `settings.inboundTag` still reads `vless-reality`. What breaks downstream is quiet rather than loud. `infra/conf/loopback.go:15` copies `inboundTag` into the generated config and `proxy/loopback/loopback.go:43` uses it as the inbound identity for traffic that returns through that outbound. So the config still loads — but every routing rule written against `vless-main` stops matching traffic that comes back through the loopback outbound, because that traffic is announced under a tag that no longer exists. The operator sees a rule that looks correct and does not fire. ### 2. The probe lane's "nothing to test here" gate reports a different message for the same outbound `testOutboundTCP` (`internal/web/service/outbound/outbound.go:160`) rejected `protocol == "blackhole" || protocol == "freedom"` exactly. A `"Freedom"` outbound fell through to the generic endpoint check, so the operator got `No testable endpoint` where the canonical spelling gets `Outbound has no testable endpoint` — two spellings of the same outbound taking different paths to the same rejection. Both reject, so this one is message precision, not a wrong result; it is fixed here because it is the same comparison and the same file family as the rest of this series. This is the last of the readers found by auditing every place the panel reads a protocol id against the core's normalization. The panel now reads the id the way the core does in all of: the outbound test tier and endpoint extractor (#6526), the Outbounds row's testability gate and Address column (#6527, #6528), and these two. ### Not changed, deliberately `server.go`'s `GetDefaultLogOutboundTags` has the same class of exact `switch obMap["protocol"]`, but it scans the **embedded** `config.json` (`//go:embed` in `setting.go:35`), whose protocols are canonical by construction — an operator cannot put `"Freedom"` there. No test can distinguish a case-insensitive read from an exact one on that input, so it is left alone rather than patched without evidence. `internal/sub`'s `clash_external.go` and `json_service.go` are canonical by construction too: they read the map built by `parseExternalLink` → `link.ParseLink`, which assigns the literals `"vmess"`, `"vless"`, `"trojan"`, `"shadowsocks"`, `"hysteria"`, `"wireguard"`. ## Type of change - [x] 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) - [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? Both fixes are red-first — the test was written and watched to fail against the current code before the fix was applied, and both were re-run with the fix reverted to confirm the red is real and not incidental. **Test 1 — `TestReplaceInboundTagInOutbounds_ReadsTheProtocolIDLikeTheCore` / `TestRemoveInboundTagFromOutbounds_ReadsTheProtocolIDLikeTheCore`** (`internal/web/service/xray_setting_routing_sync_test.go`, table-driven, no DB): | case | with the old exact comparison | with the fix | |---|---|---| | `"loopback"` | rewritten | rewritten | | `"Loopback"` | `changed = false`, tag stays `old-tag` | `changed = true`, tag is `new-tag` | | `"LOOPBACK"` | `changed = false`, tag stays `old-tag` | `changed = true`, tag is `new-tag` | | `"vmess"` (control) | untouched | untouched | The removal case asserts the same three spellings clear `inboundTag` and that `"vmess"` keeps it (`want the key gone` vs the retained value). **Test 2 — `TestTestOutboundsRejectsUntestableIDsInAnyCase`** (`internal/web/service/outbound/probe_protocol_case_test.go`), driving `TestOutbounds` with a batch payload over the real code path: ``` "Freedom" error = "No testable endpoint", want "Outbound has no testable endpoint" "FREEDOM" error = "No testable endpoint", want "Outbound has no testable endpoint" "Blackhole" error = "No testable endpoint", want "Outbound has no testable endpoint" "freedom" / "blackhole" (controls) pass both before and after ``` Reproduce the red locally: `git stash` the two non-test files, run the four tests, and the case variants fail with exactly the messages above; restore and they pass. **Local gate.** `gofmt -l` clean on all four files, `go vet` clean, `go build ./...` clean, `go test ./internal/web/service/outbound/` ok, and the four new tests green. This machine has no C compiler, so the DB-backed tests in `internal/web/service` and the CGo build itself are CI's (the panel package's DB tests cannot run locally at all — that is environmental, not this change: it fails identically on unmodified `main`). ## Screenshots / recordings N/A — backend and config-generation only, no UI change. ## Breaking changes None. Both comparisons only widen which outbounds the panel recognizes as loopback outbounds and which ids the probe gate rejects; the canonical spellings behave exactly as before, which the control cases in both tables pin. ## 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. - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [ ] 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. `go build ./...` passes here; the full `go test ./...` needs a C compiler for the SQLite driver, which CI has and this machine does not — same caveat as my previous PRs. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:03 +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#6336
No description provided.