mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5785] [Bug]: Duplication of WireGuard client IP address when using multiple inbounds #4023
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#4023
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 @AndreyOkh on GitHub (Jul 4, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5785
Describe the bug
If a client is added to multiple WireGuard inbound configurations, or if one WireGuard configuration is swapped for another, different clients might end up with the same IP address. This can lead to traffic routing issues.
How to reproduce the problem
Expected behavior
A unique IP address must be assigned to each individual WireGuard inbound connection.
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.4.2
Xray-core version
26.6.27
How did you install 3x-ui?
install.sh script
Operating system
Debian 12
Which parts of the panel are affected?
No response
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 4, 2026):
Confirmed in the code. There are two separate issues at play, both in
internal/web/service/client_wireguard.go.Root cause
WireGuard address allocation is scoped per-inbound only.
defaultWireguardClientsbuilds its "used" address set frominboundSvc.GetClients(oldInbound)— the peers already on the one inbound being written to (internal/web/service/client_inbound_apply.go, theAddInboundClientWireGuard branch). It never looks at any other inbound. Since every new WireGuard inbound defaults to the same10.0.0.0/24subnet (defaultWireguardBaseinclient_wireguard.go) unless you pick a different one, the first client added to inbound "a" and the first client added to inbound "b" each independently get10.0.0.2/32— that alone is not harmful while the two clients stay on separate inbounds (separate tunnels), but it sets up the collision.The actual duplicate-in-one-inbound bug happens at step 4. In the panel, changing a clients inbound assignment (the inbound multi-select in the client editor) is implemented as attach-to-new plus detach-from-old (
ClientService.AttachthenAddInboundClient, driven fromfrontend/src/pages/clients/ClientsPage.tsx), not a fresh allocation. A clients WireGuard keys andAllowedIPslive on the clients single shared record (ClientRecord.AllowedIPs/ToClient()ininternal/database/model/model.go) and are carried forward unchanged on attach. In the 3.4.2 source,defaultWireguardClientsonly allocates a new addressif len(c.AllowedIPs) == 0; when the client already has an address (as user1 does after being created on inbound "a"), that branch is a no-op — there is no check against the peers already present on the inbound being attached to. So user1s10.0.0.2/32is written straight into inbound "bs" peer list even though user2 already holds it there, with no error and no dedup.Status
This has already been addressed in the repository, but after v3.4.2 was tagged (2026-06-29): commit
64c30603("feat(wireguard): make client allowedIPs editable with validation", 2026-07-02) adds an explicit collision check (wireguardAllowedIPsCollision) so attaching or moving a client whose storedAllowedIPscollides with another peer already on the target inbound is now rejected with an error instead of silently applied. It is not part of any tagged release yet.Workaround on 3.4.2
settings.clients[].allowedIPsentries to a free /32 address in that inbounds subnet, then save.This reply was generated automatically by an AI agent; a maintainer may follow up.
@MHSanaei commented on GitHub (Jul 5, 2026):
This is fixed on
mainby64c30603(feat(wireguard): make client allowedIPs editable with validation), which landed after v3.4.2 was tagged — so it will ship in the next release.What changed:
wireguard: allowedIPs entry already used by another client: <addr>) instead of silently writing a duplicate peer address. The move aborts before the client is detached from the original inbound, so nothing is left half-moved.Until the next release, on 3.4.2:
allowedIPsentries to a free /32 via the inbound's raw settings JSON.Note the address is deliberately not silently re-allocated on move: a client's WireGuard address is part of the config already deployed on the device, so changing it implicitly would break the existing tunnel without warning. The explicit error + editable field keeps that decision with you.