[PR #6553] [MERGED] fix(limit-ip): leave a reverse client out of the temporary disconnect #6350

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

📋 Pull Request Information

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

Base: main ← Head: fix/limit-ip-skip-reverse-clients


📝 Commits (2)

  • 234d479 fix(limit-ip): leave a reverse client out of the temporary disconnect
  • e696699 style(limit-ip): keep the reverse-client comment within the 2-line cap

📊 Changes

2 files changed (+44 additions, -2 deletions)

View changed files

📝 internal/web/job/check_client_ip_job.go (+11 -2)
📝 internal/web/job/limit_ip_disconnect_test.go (+33 -0)

📄 Description

What breaks today

disconnectClientTemporarily handles an over-limit client by removing it from the running Xray and adding it back 100 ms later (internal/web/job/check_client_ip_job.go:669-685). For a vless client with a reverse config that cycle cannot be undone:

  1. RemoveUser → proxy/vless/inbound/inbound.go:246 → RemoveReverse (:219-226) → outboundHandlerManager.RemoveHandler(a.Reverse.Tag) (app/proxyman/outbound/outbound.go:131-146): the reverse outbound handler is deleted from the tag table.
  2. AddUser → buildUserAccount (internal/xray/api.go:544-579) builds vless.Account{Id, Flow, Testseed, Testpre} — no Reverse, even though the client config carries one.
  3. On reconnect GetReverse (inbound.go:193-201) reads the account from the validator, finds no reverse and fails with "reverse: user … is not allowed to create reverse proxy"; the handler is never rebuilt, so the tunnel stays down until Xray restarts.
  4. inbound.go:542-544 rejects forward-proxy use "for safety reasons" only while account.Reverse != nil, so after step 2 that guard no longer fires for this client either.

Reachable without unusual steps: the reverse handshake goes through dispatcher.WrapLink, which calls trackOnlineIP with the user's email and source IP — the same online-IP data this job scans — so a reverse client with Limit IP set is a normal candidate for a temporary disconnect.

The repo already encodes this constraint elsewhere: internal/xray/hot_diff.go:124-127 refuses to hot-swap an inbound when inboundHasReverseClient and forces a full restart, with a comment saying why. This job had no equivalent gate.

The change

Skip the cycle for a client whose config carries reverse, and log the skip instead of doing it silently:

if reverseClient {
    logger.Warningf("[LIMIT_IP] Not disconnecting %s: its reverse proxy config does not survive a temporary removal", clientEmail)
    return
}

What this trades, explicitly: for a reverse client the limit violation stays until the fail2ban ban catches up, which is what actually ends live traffic anyway (the removal only refuses new handshakes for 100 ms). Breaking a tunnel that needs an Xray restart to come back is the worse of the two, and it was silent.

The alternative — carrying reverse through buildUserAccount so the re-added account keeps it — is not in this PR: the removed outbound handler is not rebuilt by an account field alone, so that fix needs the core's behaviour verified against a live Xray (XRAY_E2E_BINARY), and it would change the account shape for every vless add.

Red first, with the exact output

TestDisconnectClientTemporarilySkipsReverseClient drives the function with a DB and a vless client carrying reverse, then asserts on the log: with the skip neutralised it fails because the client is removed and re-added:

--- FAIL: TestDisconnectClientTemporarilySkipsReverseClient (0.21s)

Green after the change, and it asserts the skip is reported (Not disconnecting <email>), not silent — the existing TestDisconnectClientTemporarilyAllowsHysteria still passes, so the protocol gate is untouched.

Gate

  • go test ./internal/web/job -shuffle=on — green, 9.9 s (local run through an -overlay supplying a pure-Go SQLite driver; go.mod/go.sum are unchanged).
  • gofmt clean; both comment blocks within the 2-line cap.
  • Not covered: nothing here runs against a real core, so the core-side chain above is a reading of the pinned module source, not a reproduction.

🔄 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/6553 **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/limit-ip-skip-reverse-clients` --- ### 📝 Commits (2) - [`234d479`](https://github.com/MHSanaei/3x-ui/commit/234d4790d20da936f8794593834d85a9baeba371) fix(limit-ip): leave a reverse client out of the temporary disconnect - [`e696699`](https://github.com/MHSanaei/3x-ui/commit/e696699cbe3af39decf4a6cf041dc9981b12181a) style(limit-ip): keep the reverse-client comment within the 2-line cap ### 📊 Changes **2 files changed** (+44 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/job/check_client_ip_job.go` (+11 -2) 📝 `internal/web/job/limit_ip_disconnect_test.go` (+33 -0) </details> ### 📄 Description ## What breaks today `disconnectClientTemporarily` handles an over-limit client by removing it from the running Xray and adding it back 100 ms later (`internal/web/job/check_client_ip_job.go:669-685`). For a **vless client with a reverse config** that cycle cannot be undone: 1. `RemoveUser` → `proxy/vless/inbound/inbound.go:246` → `RemoveReverse` (`:219-226`) → `outboundHandlerManager.RemoveHandler(a.Reverse.Tag)` (`app/proxyman/outbound/outbound.go:131-146`): the reverse outbound handler is deleted from the tag table. 2. `AddUser` → `buildUserAccount` (`internal/xray/api.go:544-579`) builds `vless.Account{Id, Flow, Testseed, Testpre}` — no `Reverse`, even though the client config carries one. 3. On reconnect `GetReverse` (`inbound.go:193-201`) reads the account from the validator, finds no reverse and fails with *"reverse: user … is not allowed to create reverse proxy"*; the handler is never rebuilt, so the tunnel stays down until Xray restarts. 4. `inbound.go:542-544` rejects forward-proxy use *"for safety reasons"* only while `account.Reverse != nil`, so after step 2 that guard no longer fires for this client either. Reachable without unusual steps: the reverse handshake goes through `dispatcher.WrapLink`, which calls `trackOnlineIP` with the user's email and source IP — the same online-IP data this job scans — so a reverse client with **Limit IP** set is a normal candidate for a temporary disconnect. The repo already encodes this constraint elsewhere: `internal/xray/hot_diff.go:124-127` refuses to hot-swap an inbound when `inboundHasReverseClient` and forces a full restart, with a comment saying why. This job had no equivalent gate. ## The change Skip the cycle for a client whose config carries `reverse`, and log the skip instead of doing it silently: ```go if reverseClient { logger.Warningf("[LIMIT_IP] Not disconnecting %s: its reverse proxy config does not survive a temporary removal", clientEmail) return } ``` What this trades, explicitly: for a reverse client the limit violation stays until the fail2ban ban catches up, which is what actually ends live traffic anyway (the removal only refuses *new* handshakes for 100 ms). Breaking a tunnel that needs an Xray restart to come back is the worse of the two, and it was silent. The alternative — carrying `reverse` through `buildUserAccount` so the re-added account keeps it — is not in this PR: the removed outbound handler is not rebuilt by an account field alone, so that fix needs the core's behaviour verified against a live Xray (`XRAY_E2E_BINARY`), and it would change the account shape for every vless add. ## Red first, with the exact output `TestDisconnectClientTemporarilySkipsReverseClient` drives the function with a DB and a vless client carrying `reverse`, then asserts on the log: with the skip neutralised it fails because the client *is* removed and re-added: ``` --- FAIL: TestDisconnectClientTemporarilySkipsReverseClient (0.21s) ``` Green after the change, and it asserts the skip is *reported* (`Not disconnecting <email>`), not silent — the existing `TestDisconnectClientTemporarilyAllowsHysteria` still passes, so the protocol gate is untouched. ## Gate * `go test ./internal/web/job -shuffle=on` — green, 9.9 s (local run through an `-overlay` supplying a pure-Go SQLite driver; `go.mod`/`go.sum` are unchanged). * `gofmt` clean; both comment blocks within the 2-line cap. * Not covered: nothing here runs against a real core, so the core-side chain above is a reading of the pinned module source, not a reproduction. --- <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:08 +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#6350
No description provided.