[PR #6558] [MERGED] fix(clients): keep a vless reverse client's handler across a re-add #6352

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

📋 Pull Request Information

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

Base: main ← Head: fix/vless-reverse-survives-readd


📝 Commits (2)

  • a54894f fix(clients): keep a vless reverse client's handler across a re-add
  • 67159b6 refactor(clients): drop an account map helper nothing calls

📊 Changes

6 files changed (+231 additions, -0 deletions)

View changed files

📝 internal/web/service/client_bulk.go (+1 -0)
📝 internal/web/service/client_inbound_apply.go (+2 -0)
➕ internal/web/service/client_reverse_readd_test.go (+149 -0)
📝 internal/web/service/inbound_traffic.go (+1 -0)
📝 internal/xray/api.go (+24 -0)
➕ internal/xray/api_reverse_test.go (+54 -0)

📄 Description

The bug

RemoveUser does two things to a VLESS client: it drops the credential, and it
drops the client's reverse outbound handler (RemoveReverse →
outboundManager.RemoveHandler). Every live remove/re-add path in the panel
rebuilds the account from a hand-built map, and buildUserAccount read
id, flow, testseed and testpre — never reverse. So a reverse client
that was removed and added back could still authenticate, but its tunnel stayed
down until Xray restarted, with nothing logged. The account type is what decides
this: GetReverse refuses with user … is not allowed to create reverse proxy
when the stored account has no tag.

claude's review of #6553 found the quota path; the same defect is on four
paths, all of which this PR fixes:

Path Trigger
client_inbound_apply.go:1040 editing a client (comment, expiry, totalGB, limitIp…) — the most ordinary action
client_bulk.go:1802 bulk re-enable from the client list
inbound_traffic.go:727 traffic reset: a depleted client is removed and re-added on every renewal
client_inbound_apply.go:611, runtime/local.go adding a client to an inbound that already has one, and the local runtime adds both node-push paths go through

The LIMIT_IP job is deliberately untouched: it now skips reverse clients entirely
(#6553), so it never removes one.

The fix

buildUserAccount carries the tag, reading it from either shape a caller can
hold — the settings JSON object or the typed client value — via a small
reverseTag helper. The five account maps those paths build now include the
client's reverse, and the two identical maps in internal/web/runtime/local.go
became one clientUserMap so a field can no longer be missing from one of them
only.

Not changed, deliberately:

  • The account shape for every other protocol, and for a vless client without a
    reverse — nothing is sent when the tag is empty.
  • The hot-swap path in internal/xray/hot_diff.go, which already refuses to
    hot-swap any inbound carrying a reverse client and restarts instead.
  • The four account maps that differ in which fields they carry (some omit
    WireGuard keys). Unifying them would change what a bulk enable sends to a
    WireGuard inbound, which is a behaviour change this fix does not need.

Core chain, read from the pinned xray-core

Static reading of xray-core@v1.260327.1-0.20260908222543-52a412d9e2f5:

  1. AddUserOperation.ApplyInbound → op.User.ToMemoryUser()
    (app/proxyman/command/command.go:38-52).
  2. User.GetTypedAccount() deserialises the typed message into the registered
    *vless.Account (common/protocol/user.go:8-24).
  3. vless.Account.AsAccount() copies Reverse: a.Reverse into the
    MemoryAccount the validator stores (proxy/vless/account.go:24).
  4. Handler.GetReverse rebuilds the handler from the stored account's
    Reverse.Tag on the client's next reverse-command connection
    (proxy/vless/inbound/inbound.go:193-205).

No -test/live-core run backs this: XRAY_E2E_BINARY is set by no CI job, so
the chain is a reading of the module source, not a reproduction.

Red first

Every test fails on the commit before the fix:

--- FAIL: TestBuildUserAccountCarriesTheReverseTag/settings_json_shape  the account carries reverse tag "", want "portal"
--- FAIL: TestBuildUserAccountCarriesTheReverseTag/typed_client_field   the account carries reverse tag "", want "portal"
--- FAIL: TestClientUserMapCarriesTheReverseTag                        the map carries reverse <nil>, want the client's own *ClientReverse
--- FAIL: TestClientEditKeepsTheReverseTag                             the re-add of rev-edit@example.test carries reverse <nil>, want its stored tag portal
--- FAIL: TestBulkReEnableKeepsTheReverseTag                           the re-add of rev-bulk@example.test carries reverse <nil>, want its stored tag portal
--- FAIL: TestTrafficResetKeepsTheReverseTag                           the re-add of rev-quota@example.test carries reverse <nil>, want its stored tag portal
--- FAIL: TestAddingClientsKeepsTheReverseTag                          the re-add of rev-add-second@example.test carries reverse <nil>, want its stored tag portal

The four service tests drive the real service methods (ClientService.Update,
BulkSetEnable, ResetClientTraffic, AddInboundClient) against a real temp
DB, with the runtime override recording the maps the panel would push.

Gate

  • go test over internal/xray, internal/web/runtime, internal/web/service,
    internal/web/job, internal/web/controller — green (the DB-backed service
    suite via an -overlay supplying a pure-Go SQLite driver; go.mod/go.sum
    are unchanged).
  • gofmt clean, added comment blocks within the 2-line cap.
  • Not covered here: the live-core behaviour above, and PostgreSQL
    (postgres-durable-first is the CI job that would).

🔄 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/6558 **Author:** [@BlindMaster24](https://github.com/BlindMaster24) **Created:** 9/15/2026 **Status:** ✅ Merged **Merged:** 9/15/2026 **Merged by:** [@BlindMaster24](https://github.com/BlindMaster24) **Base:** `main` ← **Head:** `fix/vless-reverse-survives-readd` --- ### 📝 Commits (2) - [`a54894f`](https://github.com/MHSanaei/3x-ui/commit/a54894f848f4594ab0fe2c90975e247c085db5ef) fix(clients): keep a vless reverse client's handler across a re-add - [`67159b6`](https://github.com/MHSanaei/3x-ui/commit/67159b68dd3d291975f5df325bab16119f9a6515) refactor(clients): drop an account map helper nothing calls ### 📊 Changes **6 files changed** (+231 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/client_bulk.go` (+1 -0) 📝 `internal/web/service/client_inbound_apply.go` (+2 -0) ➕ `internal/web/service/client_reverse_readd_test.go` (+149 -0) 📝 `internal/web/service/inbound_traffic.go` (+1 -0) 📝 `internal/xray/api.go` (+24 -0) ➕ `internal/xray/api_reverse_test.go` (+54 -0) </details> ### 📄 Description ## The bug `RemoveUser` does two things to a VLESS client: it drops the credential, and it drops the client's reverse outbound handler (`RemoveReverse` → `outboundManager.RemoveHandler`). Every live remove/re-add path in the panel rebuilds the account from a hand-built map, and `buildUserAccount` read `id`, `flow`, `testseed` and `testpre` — never `reverse`. So a reverse client that was removed and added back could still authenticate, but its tunnel stayed down until Xray restarted, with nothing logged. The account type is what decides this: `GetReverse` refuses with `user … is not allowed to create reverse proxy` when the stored account has no tag. `claude`'s review of #6553 found the quota path; the same defect is on four paths, all of which this PR fixes: | Path | Trigger | |---|---| | `client_inbound_apply.go:1040` | editing a client (comment, expiry, totalGB, limitIp…) — the most ordinary action | | `client_bulk.go:1802` | bulk re-enable from the client list | | `inbound_traffic.go:727` | traffic reset: a depleted client is removed and re-added on every renewal | | `client_inbound_apply.go:611`, `runtime/local.go` | adding a client to an inbound that already has one, and the local runtime adds both node-push paths go through | The LIMIT_IP job is deliberately untouched: it now skips reverse clients entirely (#6553), so it never removes one. ## The fix `buildUserAccount` carries the tag, reading it from either shape a caller can hold — the settings JSON object or the typed client value — via a small `reverseTag` helper. The five account maps those paths build now include the client's `reverse`, and the two identical maps in `internal/web/runtime/local.go` became one `clientUserMap` so a field can no longer be missing from one of them only. Not changed, deliberately: - The account shape for every other protocol, and for a vless client without a reverse — nothing is sent when the tag is empty. - The hot-swap path in `internal/xray/hot_diff.go`, which already refuses to hot-swap any inbound carrying a reverse client and restarts instead. - The four account maps that differ in which fields they carry (some omit WireGuard keys). Unifying them would change what a bulk enable sends to a WireGuard inbound, which is a behaviour change this fix does not need. ## Core chain, read from the pinned `xray-core` Static reading of `xray-core@v1.260327.1-0.20260908222543-52a412d9e2f5`: 1. `AddUserOperation.ApplyInbound` → `op.User.ToMemoryUser()` (`app/proxyman/command/command.go:38-52`). 2. `User.GetTypedAccount()` deserialises the typed message into the registered `*vless.Account` (`common/protocol/user.go:8-24`). 3. `vless.Account.AsAccount()` copies `Reverse: a.Reverse` into the `MemoryAccount` the validator stores (`proxy/vless/account.go:24`). 4. `Handler.GetReverse` rebuilds the handler from the stored account's `Reverse.Tag` on the client's next reverse-command connection (`proxy/vless/inbound/inbound.go:193-205`). No `-test`/live-core run backs this: `XRAY_E2E_BINARY` is set by no CI job, so the chain is a reading of the module source, not a reproduction. ## Red first Every test fails on the commit before the fix: ``` --- FAIL: TestBuildUserAccountCarriesTheReverseTag/settings_json_shape the account carries reverse tag "", want "portal" --- FAIL: TestBuildUserAccountCarriesTheReverseTag/typed_client_field the account carries reverse tag "", want "portal" --- FAIL: TestClientUserMapCarriesTheReverseTag the map carries reverse <nil>, want the client's own *ClientReverse --- FAIL: TestClientEditKeepsTheReverseTag the re-add of rev-edit@example.test carries reverse <nil>, want its stored tag portal --- FAIL: TestBulkReEnableKeepsTheReverseTag the re-add of rev-bulk@example.test carries reverse <nil>, want its stored tag portal --- FAIL: TestTrafficResetKeepsTheReverseTag the re-add of rev-quota@example.test carries reverse <nil>, want its stored tag portal --- FAIL: TestAddingClientsKeepsTheReverseTag the re-add of rev-add-second@example.test carries reverse <nil>, want its stored tag portal ``` The four service tests drive the real service methods (`ClientService.Update`, `BulkSetEnable`, `ResetClientTraffic`, `AddInboundClient`) against a real temp DB, with the runtime override recording the maps the panel would push. ## Gate - `go test` over `internal/xray`, `internal/web/runtime`, `internal/web/service`, `internal/web/job`, `internal/web/controller` — green (the DB-backed service suite via an `-overlay` supplying a pure-Go SQLite driver; `go.mod`/`go.sum` are unchanged). - `gofmt` clean, added comment blocks within the 2-line cap. - Not covered here: the live-core behaviour above, and PostgreSQL (`postgres-durable-first` is the CI job that would). --- <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:10 +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#6352
No description provided.