mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6119] [Bug]: MTProto inbound does not log client IP addresses, IP Limit non-functional #4228
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4228
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
mtgbinary), 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 theclient_ipstable.How to reproduce the problem
mtproto(this uses the internalmtgby default).IP Limit = 3in the client settings.journalctl -u x-ui -f— real client IPs are visible.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
@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 Limitare 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-33states this, andcollectFromOnlineAPI(same file, lines 88-116) is the only collector. It callsXrayService.GetOnlineUsers(), which resolves tointernal/xray/api.go:735and a singleStatsService.GetUsersStatsgRPC call to Xray-core.Title: MTProto (mtg) inbounds never populate
inbound_client_ips, soIP Limitis silently ignored for their clientsSeverity: Medium
Category: Correctness
Why this matters: the client form exposes
limitIpfor MTProto clients (frontend/src/schemas/protocols/inbound/mtproto.ts:26; the field infrontend/src/pages/clients/ClientFormModal.tsxis gated only on Fail2ban availability, not on protocol), anddocs/content/docs/en/config/clients.mdx:20lists Limit IP as applying to "all" protocols. An operator who setsIP Limit = 3on an MTProto client gets no enforcement and no warning, exactly as you observed.The chain, as far as I could trace it:
mtg-multisidecar, not in Xray (internal/mtproto/process.go:1-8). They therefore never appear inGetUsersStats, which is the only input to the IP job./stats, decoded intostatsUseratinternal/mtproto/manager.go:615-619—connections,bytes_in,bytes_out. No per-connection IP field is read, andCollectTraffic(line 402) returns only byte deltas plus a list of online emails.internal/web/job/mtproto_job.gofeeds those intoAddTrafficandRefreshLocalOnlineClientsonly. Nothing on that path writesinbound_client_ips, which is the table the panel's IP log reads from — hence "No IP Record".client-ipfield you see injournalctlis mtg's own structured log line, forwarded verbatim byprocLogWriter.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 handlesvmess,vless,trojanandshadowsocksand logsTemporary disconnect is not supported for protocol %sfor 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-multifork's API and merge them into the sameinbound_client_ipspath the online-stats collector uses, then extend the disconnect switch to covermtprotovia the fork's management API. If that is not wanted, the honest short-term fix is to hide or disablelimitIpfor MTProto clients and correct the "all protocols" row indocs/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-multicurrently 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 ininternal/web/translation/en-US.json:526as "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 replaceIP Limit. Per-clienttotalGBandexpiryTimedo 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.
@tarasov2783-ux commented on GitHub (Jul 27, 2026):
.