[GH-ISSUE #6119] [Bug]: MTProto inbound does not log client IP addresses, IP Limit non-functional #4228

Closed
opened 2026-10-31 20:38:08 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @tarasov2783-ux on GitHub (Jul 27, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6119

Describe the bug

When creating an MTProto inbound (which uses the built‑in mtg binary), the panel does not provide a "Log IP" option. As a result, client IP addresses are not saved to the panel's database, and the IP Limit feature does not work. Clients can connect from an unlimited number of IPs simultaneously. The system logs (journalctl -u x-ui) do show real client IPs (e.g., "client-ip":"1.2.3.4"), but they are not stored in the client_ips table.

How to reproduce the problem

  1. Install 3x‑UI version 3.5.0.
  2. Create an inbound with protocol mtproto (this uses the internal mtg by default).
  3. Observe that in the inbound settings there is no "Log IP" toggle (unlike VLESS/VMess/Trojan).
  4. Create a client and set IP Limit = 3 in the client settings.
  5. Connect to the MTProto proxy from several different IP addresses.
  6. Check system logs: journalctl -u x-ui -f — real client IPs are visible.
  7. Go to the panel → "Client traffic" → "IP logs" for the client — no IP records are shown.

Expected behavior

The panel should provide the "Log IP" option for MTProto inbounds (just like for other protocols). When enabled, IP addresses should be saved and the IP Limit should work.

Actual behavior

The "Log IP" option is missing for MTProto inbounds, so IPs are not logged and IP Limit cannot function.

Relevant logs

Panel logs show real client IPs (from mtg), but they are not recorded in the database:
root@mtpanel2:~# journalctl -u x-ui -f
Jul 27 09:49:55 mtpanel2 /usr/local/x-ui/x-ui[1131309]: INFO - mtproto: mtg inbound 1 | {"level":"info","client-ip":"1.2.3.4","stream-id":"5GJFAOfDDigmsWCl-gCo_w","logger":"proxy","timestamp":1785145795341,"message":"Stream has been started"}

text

Screenshots

No response

3x-ui version

3.5.0

Xray-core version

26.6.27

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24.04

Which parts of the panel are affected?

IP Logging, IP Limit, MTProto inbound

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

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 @tarasov2783-ux on GitHub (Jul 27, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6119 ### Describe the bug When creating an MTProto inbound (which uses the built‑in `mtg` binary), the panel does not provide a **"Log IP"** option. As a result, client IP addresses are not saved to the panel's database, and the **IP Limit** feature does not work. Clients can connect from an unlimited number of IPs simultaneously. The system logs (`journalctl -u x-ui`) do show real client IPs (e.g., `"client-ip":"1.2.3.4"`), but they are not stored in the `client_ips` table. ### How to reproduce the problem 1. Install 3x‑UI version 3.5.0. 2. Create an inbound with protocol `mtproto` (this uses the internal `mtg` by default). 3. Observe that in the inbound settings there is **no** "Log IP" toggle (unlike VLESS/VMess/Trojan). 4. Create a client and set `IP Limit = 3` in the client settings. 5. Connect to the MTProto proxy from several different IP addresses. 6. Check system logs: `journalctl -u x-ui -f` — real client IPs **are** visible. 7. Go to the panel → "Client traffic" → "IP logs" for the client — no IP records are shown. ### Expected behavior The panel should provide the "Log IP" option for MTProto inbounds (just like for other protocols). When enabled, IP addresses should be saved and the IP Limit should work. ### Actual behavior The "Log IP" option is missing for MTProto inbounds, so IPs are not logged and IP Limit cannot function. ### Relevant logs Panel logs show real client IPs (from mtg), but they are not recorded in the database: root@mtpanel2:~# journalctl -u x-ui -f Jul 27 09:49:55 mtpanel2 /usr/local/x-ui/x-ui[1131309]: INFO - mtproto: mtg inbound 1 | {"level":"info","client-ip":"1.2.3.4","stream-id":"5GJFAOfDDigmsWCl-gCo_w","logger":"proxy","timestamp":1785145795341,"message":"Stream has been started"} text ### Screenshots _No response_ ### 3x-ui version 3.5.0 ### Xray-core version 26.6.27 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24.04 ### Which parts of the panel are affected? IP Logging, IP Limit, MTProto inbound ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### 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:38:08 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jul 27, 2026):

Confirmed in the source: the panel has no source of client IPs for MTProto inbounds, so both the IP log and IP Limit are inert for them. Detail below.

One correction to the reproduction steps: there is no per-inbound "Log IP" option for any protocol in 3.5.0. IP collection no longer reads an access log at all — internal/web/job/check_client_ip_job.go:30-33 states this, and collectFromOnlineAPI (same file, lines 88-116) is the only collector. It calls XrayService.GetOnlineUsers(), which resolves to internal/xray/api.go:735 and a single StatsService.GetUsersStats gRPC call to Xray-core.

Title: MTProto (mtg) inbounds never populate inbound_client_ips, so IP Limit is silently ignored for their clients

Severity: Medium

Category: Correctness

Why this matters: the client form exposes limitIp for MTProto clients (frontend/src/schemas/protocols/inbound/mtproto.ts:26; the field in frontend/src/pages/clients/ClientFormModal.tsx is gated only on Fail2ban availability, not on protocol), and docs/content/docs/en/config/clients.mdx:20 lists Limit IP as applying to "all" protocols. An operator who sets IP Limit = 3 on an MTProto client gets no enforcement and no warning, exactly as you observed.

The chain, as far as I could trace it:

  1. MTProto connections terminate in the mtg-multi sidecar, not in Xray (internal/mtproto/process.go:1-8). They therefore never appear in GetUsersStats, which is the only input to the IP job.
  2. The only data the panel scrapes back from mtg is /stats, decoded into statsUser at internal/mtproto/manager.go:615-619 — connections, bytes_in, bytes_out. No per-connection IP field is read, and CollectTraffic (line 402) returns only byte deltas plus a list of online emails.
  3. internal/web/job/mtproto_job.go feeds those into AddTraffic and RefreshLocalOnlineClients only. Nothing on that path writes inbound_client_ips, which is the table the panel's IP log reads from — hence "No IP Record".
  4. The client-ip field you see in journalctl is mtg's own structured log line, forwarded verbatim by procLogWriter.emitLocked (internal/mtproto/process.go:95-102). It is written to the panel log and never parsed.

A second gap sits behind the first: even with IPs collected, disconnectClientTemporarily (internal/web/job/check_client_ip_job.go:616-622) only handles vmess, vless, trojan and shadowsocks and logs Temporary disconnect is not supported for protocol %s for anything else. The Fail2ban ban itself is packet-level and protocol-agnostic, so that part would still work, but the forced disconnect would not.

Recommendation (for the maintainers to weigh — I am not opening a PR): surface per-secret source IPs from the mtg-multi fork's API and merge them into the same inbound_client_ips path the online-stats collector uses, then extend the disconnect switch to cover mtproto via the fork's management API. If that is not wanted, the honest short-term fix is to hide or disable limitIp for MTProto clients and correct the "all protocols" row in docs/content/docs/en/config/clients.mdx, so the setting stops promising enforcement it cannot deliver.

Confidence: high for the panel-side chain above, since it is all in this repository. Lower for the fix, because whether mtg-multi currently exposes per-secret client IPs over its API is outside this repo and I could not verify it here.

Partial workaround available today: the MTProto inbound has a Max connections field (throttleMaxConnections, internal/mtproto/manager.go:569-571), described in internal/web/translation/en-US.json:526 as "Cap concurrent connections across all users with a fair-share limit." It is an inbound-wide connection cap, not a per-client or per-IP limit, so it does not replace IP Limit. Per-client totalGB and expiryTime do work on MTProto — they are mapped to the sidecar's [secret-limits] section (internal/mtproto/manager.go:586-597).

Two other open IP-limit reports, #6100 and #6097, are unrelated to this one (Xray-native inbounds, different causes), so this stays separate.

@MHSanaei for a decision on which direction to take.

This reply was generated automatically. A maintainer may follow up.

<!-- gh-comment-id:5090057215 --> @github-actions[bot] commented on GitHub (Jul 27, 2026): Confirmed in the source: the panel has no source of client IPs for MTProto inbounds, so both the IP log and `IP Limit` are inert for them. Detail below. One correction to the reproduction steps: there is no per-inbound "Log IP" option for any protocol in 3.5.0. IP collection no longer reads an access log at all — `internal/web/job/check_client_ip_job.go:30-33` states this, and `collectFromOnlineAPI` (same file, lines 88-116) is the only collector. It calls `XrayService.GetOnlineUsers()`, which resolves to `internal/xray/api.go:735` and a single `StatsService.GetUsersStats` gRPC call to Xray-core. Title: MTProto (mtg) inbounds never populate `inbound_client_ips`, so `IP Limit` is silently ignored for their clients Severity: Medium Category: Correctness Why this matters: the client form exposes `limitIp` for MTProto clients (`frontend/src/schemas/protocols/inbound/mtproto.ts:26`; the field in `frontend/src/pages/clients/ClientFormModal.tsx` is gated only on Fail2ban availability, not on protocol), and `docs/content/docs/en/config/clients.mdx:20` lists **Limit IP** as applying to "all" protocols. An operator who sets `IP Limit = 3` on an MTProto client gets no enforcement and no warning, exactly as you observed. The chain, as far as I could trace it: 1. MTProto connections terminate in the `mtg-multi` sidecar, not in Xray (`internal/mtproto/process.go:1-8`). They therefore never appear in `GetUsersStats`, which is the only input to the IP job. 2. The only data the panel scrapes back from mtg is `/stats`, decoded into `statsUser` at `internal/mtproto/manager.go:615-619` — `connections`, `bytes_in`, `bytes_out`. No per-connection IP field is read, and `CollectTraffic` (line 402) returns only byte deltas plus a list of online emails. 3. `internal/web/job/mtproto_job.go` feeds those into `AddTraffic` and `RefreshLocalOnlineClients` only. Nothing on that path writes `inbound_client_ips`, which is the table the panel's IP log reads from — hence "No IP Record". 4. The `client-ip` field you see in `journalctl` is mtg's own structured log line, forwarded verbatim by `procLogWriter.emitLocked` (`internal/mtproto/process.go:95-102`). It is written to the panel log and never parsed. A second gap sits behind the first: even with IPs collected, `disconnectClientTemporarily` (`internal/web/job/check_client_ip_job.go:616-622`) only handles `vmess`, `vless`, `trojan` and `shadowsocks` and logs `Temporary disconnect is not supported for protocol %s` for anything else. The Fail2ban ban itself is packet-level and protocol-agnostic, so that part would still work, but the forced disconnect would not. Recommendation (for the maintainers to weigh — I am not opening a PR): surface per-secret source IPs from the `mtg-multi` fork's API and merge them into the same `inbound_client_ips` path the online-stats collector uses, then extend the disconnect switch to cover `mtproto` via the fork's management API. If that is not wanted, the honest short-term fix is to hide or disable `limitIp` for MTProto clients and correct the "all protocols" row in `docs/content/docs/en/config/clients.mdx`, so the setting stops promising enforcement it cannot deliver. Confidence: high for the panel-side chain above, since it is all in this repository. Lower for the fix, because whether `mtg-multi` currently exposes per-secret client IPs over its API is outside this repo and I could not verify it here. Partial workaround available today: the MTProto inbound has a **Max connections** field (`throttleMaxConnections`, `internal/mtproto/manager.go:569-571`), described in `internal/web/translation/en-US.json:526` as "Cap concurrent connections across all users with a fair-share limit." It is an inbound-wide connection cap, not a per-client or per-IP limit, so it does not replace `IP Limit`. Per-client `totalGB` and `expiryTime` do work on MTProto — they are mapped to the sidecar's `[secret-limits]` section (`internal/mtproto/manager.go:586-597`). Two other open IP-limit reports, #6100 and #6097, are unrelated to this one (Xray-native inbounds, different causes), so this stays separate. @MHSanaei for a decision on which direction to take. *This reply was generated automatically. A maintainer may follow up.*
Author
Owner

@tarasov2783-ux commented on GitHub (Jul 27, 2026):

.

<!-- gh-comment-id:5090166274 --> @tarasov2783-ux commented on GitHub (Jul 27, 2026): .
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#4228
No description provided.