[GH-ISSUE #5248] [Bug]: ip limit problem #3673

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

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

Describe the bug

in some clients, there is this problem that ip limit doesn't work properly.
it's only 1 internet on 1 device connected to it but it shows many IPs connected. this bug has been there since v3
sometimes it goes up to 50 IPs connected to 1 client in only a couple of minutes and the usage of it is normal(it's like 1 customer using it only, not 50)
i've read all patches whenever an update was dropped hoping this problem would be fixed but never got fixed.

How to reproduce the problem

i really don't know but it happens by chance on some clients, happend to me right now so i'm sure it's not a fake acting from my customers, although 50 IPs connected in a few minutes was enough to prove.

Expected behavior

1 IP connected

Actual behavior

up to 50 IPs connected in 1-2 minutes

Relevant logs


Screenshots

Image

3x-ui version

3.3.1

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

ubuntu 22.04

Which parts of the panel are affected?

Statistics / traffic counters

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

Yes — Cloudflare (proxied DNS)

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 @NewMreza on GitHub (Jun 12, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5248 ### Describe the bug in some clients, there is this problem that ip limit doesn't work properly. it's only 1 internet on 1 device connected to it but it shows many IPs connected. this bug has been there since v3 sometimes it goes up to 50 IPs connected to 1 client in only a couple of minutes and the usage of it is normal(it's like 1 customer using it only, not 50) i've read all patches whenever an update was dropped hoping this problem would be fixed but never got fixed. ### How to reproduce the problem i really don't know but it happens by chance on some clients, happend to me right now so i'm sure it's not a fake acting from my customers, although 50 IPs connected in a few minutes was enough to prove. ### Expected behavior 1 IP connected ### Actual behavior up to 50 IPs connected in 1-2 minutes ### Relevant logs ```shell ``` ### Screenshots <img width="583" height="275" alt="Image" src="https://github.com/user-attachments/assets/0f591885-48f7-4ab4-b023-7b51204bbaa3" /> ### 3x-ui version 3.3.1 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system ubuntu 22.04 ### Which parts of the panel are affected? Statistics / traffic counters ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? Yes — Cloudflare (proxied DNS) ### 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:09 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

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

The root cause here is Cloudflare's proxied (orange-cloud) DNS mode, not a bug in the IP limit logic itself.

Why you see dozens of IPs for one device

When Cloudflare proxies traffic, the TCP connection to your origin server is made by a Cloudflare edge node, not by the client directly. Each new or reused connection can arrive from a different Cloudflare edge IP. Xray's statsUserOnline policy — and, in the fallback path, the access log — both record the TCP source address, which is whichever Cloudflare edge server handled that connection. A single mobile client generating a handful of reconnects in a few minutes can produce 20–50 distinct Cloudflare edge addresses; the panel displays exactly what Xray reports.

Confirmed in source

The IP addresses displayed by the panel come from the Xray core's online-stats gRPC API (internal/xray/api.go:GetOnlineUsers) or from access-log parsing (internal/web/job/check_client_ip_job.go:processLogFile). Neither path does any filtering or rewriting of those source IPs — the panel shows them as-is.

Fix: configure trustedXForwardedFor on the inbound

Xray has a sockopt option called trustedXForwardedFor. When a connection arrives from a CIDR listed there, Xray reads the X-Forwarded-For header (which Cloudflare sets to the real client IP) and uses that value as the connection's source address for logging and stats. Configuring it with Cloudflare's published IP ranges will make IP limit count real client IPs instead of Cloudflare edge IPs.

The panel exposes this field in the inbound editor: Transport tab → Socket Settings → Trusted X-Forwarded-For (confirmed in frontend/src/pages/inbounds/form/transport/sockopt.tsx).

Steps:

  1. Open the inbound in the panel editor.
  2. Go to the Transport tab, then Socket Settings.
  3. In the Trusted X-Forwarded-For field, add Cloudflare's IPv4 and IPv6 CIDR ranges. The canonical list is published by Cloudflare at:
  4. Save and restart Xray (or use Restart Xray in the panel).

Prerequisites

  • This only applies to HTTP-based transports (WebSocket, XHTTP, HTTPUpgrade, gRPC) — the only transports that can pass through Cloudflare's proxy. TCP/Raw and other non-HTTP transports cannot be Cloudflare-proxied.
  • The running Xray-core must support trustedXForwardedFor in sockopt. The bundled core in 3.3.1 (v1.260327.1-0.20260601021109-94ffd50060f1) is recent enough.

Why only some clients are affected

Clients connecting directly to the origin (without Cloudflare proxy) show one real IP. Only those whose traffic routes through Cloudflare's edge exhibit the inflated count.


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

<!-- gh-comment-id:4696604431 --> @github-actions[bot] commented on GitHub (Jun 12, 2026): The root cause here is Cloudflare's proxied (orange-cloud) DNS mode, not a bug in the IP limit logic itself. **Why you see dozens of IPs for one device** When Cloudflare proxies traffic, the TCP connection to your origin server is made by a Cloudflare edge node, not by the client directly. Each new or reused connection can arrive from a different Cloudflare edge IP. Xray's `statsUserOnline` policy — and, in the fallback path, the access log — both record the **TCP source address**, which is whichever Cloudflare edge server handled that connection. A single mobile client generating a handful of reconnects in a few minutes can produce 20–50 distinct Cloudflare edge addresses; the panel displays exactly what Xray reports. **Confirmed in source** The IP addresses displayed by the panel come from the Xray core's online-stats gRPC API (`internal/xray/api.go:GetOnlineUsers`) or from access-log parsing (`internal/web/job/check_client_ip_job.go:processLogFile`). Neither path does any filtering or rewriting of those source IPs — the panel shows them as-is. **Fix: configure `trustedXForwardedFor` on the inbound** Xray has a `sockopt` option called `trustedXForwardedFor`. When a connection arrives from a CIDR listed there, Xray reads the `X-Forwarded-For` header (which Cloudflare sets to the real client IP) and uses that value as the connection's source address for logging and stats. Configuring it with Cloudflare's published IP ranges will make IP limit count real client IPs instead of Cloudflare edge IPs. The panel exposes this field in the inbound editor: **Transport tab → Socket Settings → Trusted X-Forwarded-For** (confirmed in `frontend/src/pages/inbounds/form/transport/sockopt.tsx`). Steps: 1. Open the inbound in the panel editor. 2. Go to the **Transport** tab, then **Socket Settings**. 3. In the **Trusted X-Forwarded-For** field, add Cloudflare's IPv4 and IPv6 CIDR ranges. The canonical list is published by Cloudflare at: - https://www.cloudflare.com/ips-v4 - https://www.cloudflare.com/ips-v6 4. Save and restart Xray (or use **Restart Xray** in the panel). **Prerequisites** - This only applies to HTTP-based transports (WebSocket, XHTTP, HTTPUpgrade, gRPC) — the only transports that can pass through Cloudflare's proxy. TCP/Raw and other non-HTTP transports cannot be Cloudflare-proxied. - The running Xray-core must support `trustedXForwardedFor` in sockopt. The bundled core in 3.3.1 (`v1.260327.1-0.20260601021109-94ffd50060f1`) is recent enough. **Why only some clients are affected** Clients connecting directly to the origin (without Cloudflare proxy) show one real IP. Only those whose traffic routes through Cloudflare's edge exhibit the inflated count. --- *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#3673
No description provided.