mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6372] [Bug]: Editing a client overwrites all WireGuard/AmneziaWG peers with one config, breaking tunnels on the other nodes #4325
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#4325
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 @stepm65 on GitHub (Aug 31, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6372
Describe the bug
Each WireGuard peer has its own key pair, preshared key, tunnel address and subnet, so
a client added to several WG/AWG inbounds is really several independent peers.
The client edit form exposes a single set of peer fields — one address, one key pair —
even when the client exists in four inbounds across four nodes with different subnets.
Saving that form writes those single values to every inbound the client belongs to.
The result is four peers with identical keys and an identical tunnel address. Three of
them now sit in the wrong subnet, and their tunnels stop working. The original per-node
keys and addresses are gone — there is no way to recover them from the panel, the
affected peers have to be recreated by hand.
This is the writable counterpart of #6346 , where the config section
showed only the first config. There it was a display problem; here the same
single-config assumption destroys the other peers' data on save.
How to reproduce the problem
(e.g. 10.10.151.0/24, 10.10.152.0/24, ...).
own key pair and address, and all four tunnels work.
peer now carries the same keys and the same address. Tunnels on three of the four
nodes are broken.
Expected behavior
The form should list every inbound the client belongs to, each with its own editable
address, key pair and preshared key, labelled with the inbound remark — the same way the
"Copy link" section already enumerates them.
Saving must apply per peer: editing the DE peer must leave the FI, TR and NL peers
untouched. At minimum, until per-peer editing exists, the form should not write WG peer
parameters to inbounds it did not load them from.
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.7.0
Xray-core version
No response
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 24.04
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 (Aug 31, 2026):
Confirmed — this is a real bug and it is still present on the default branch (
f727d04f, the v3.7.0 tag you are running). Saving the client edit form does broadcast one set of WireGuard peer parameters to every WG/AWG inbound the client is attached to. Your diagnosis of the cause is correct; the detail below refines which fields are lost for which protocol.What actually happens
Frontend — the form can only represent one wg inbound and one awg inbound.
resolveTunnelAllowedIPsByInboundpicks the first attached inbound of each protocol, and nothing else (frontend/src/pages/clients/ClientFormModal.tsx:218):The same "first match wins" rule seeds the form on open (
ClientFormModal.tsx:342-347), so with four WG inbounds you only ever see inbound #1's address.Worse, the per-inbound override is only sent at all when both protocols are attached at once (
ClientFormModal.tsx:701):Four WireGuard inbounds means
showAmneziawg === false, soallowedIPsByInboundis never populated and the code falls through to the single broadcast value atClientFormModal.tsx:717-719. The keys are unconditional (ClientFormModal.tsx:695-696):Backend — the only guard is AmneziaWG-only, and it only covers the address.
ClientService.Updateloops over every attached inbound and copies the oneupdatedclient into each (internal/web/service/client_crud.go:519-533). The protective branch isaddressesFitAmneziaWGInbound, and its first statement is (client_crud.go:758-760):For
model.WireGuardit returnstrueunconditionally, soclientForInbound.AllowedIPsis never cleared and inbound #1's address is written verbatim into inbounds #2–#4.UpdateInboundClientthen accepts it, because its carry-forward only fires when the incoming field is empty (internal/web/service/client_inbound_apply.go:696-703):and its collision check (
client_inbound_apply.go:714-723) only compares against other clients on the same inbound, never against that inbound's own subnet — so10.10.151.5/32lands in a10.10.152.0/24inbound without complaint. The values are stamped into the settings JSON atclient_inbound_apply.go:790-799.So, precisely:
addressesFitAmneziaWGInboundguard fires)There is no
privateKeyByInboundcounterpart toallowedIPsByInboundanywhere in the tree, which is why the key broadcast survives even where the address guard works.model.ClientRecorditself has exactly one column per field (internal/database/model/model.go:926-929:wg_private_key,wg_public_key,wg_allowed_ips,wg_pre_shared_key) — per-peer values live only in each inbound's ownsettingsJSON, which is what the form cannot reach.internal/web/service/client_update_allowedips_test.go:60(TestUpdateBroadcastAllowedIPsDoesNotOverwriteOtherInboundWhenMismatched) pins exactly this bug class — but only for the one-wg-plus-one-awg pair. There is no test for two inbounds of the same protocol, which is why your case slipped through.Workaround until this is fixed
The API route accepts an undocumented
inboundIdsquery parameter that scopes the update to specific inbounds (internal/web/controller/client.go:210-211→ the filter atclient_crud.go:414-426). The panel UI never sends it, but you can:That touches inbound 7 only and leaves the other three peers alone. For addresses specifically,
allowedIPsByInbound(model.go:891) is honoured for any inbound id, on any protocol, in a single call — it is only the UI that refuses to build it. Note the body replaces the client rather than patching it, so send the full field set you want to keep.On recovery: the original per-peer values are not only in the record — each inbound's
settingsJSON in/etc/x-ui/x-ui.dbcarries its own peer entry, so a database backup taken before the save still has all four. If you have one, that is faster than recreating by hand.Also: your report references
#<номер прошлого тикета>with the placeholder unfilled. I believe you mean #6346, your own read-side report. They are the same single-config assumption but two different code paths (display vs. save), so I have linked rather than merged them.Verdict: Confirmed bug
Severity: High
Confidence: High
Root cause:
ClientService.Updateatinternal/web/service/client_crud.go:519-533copies onemodel.Clientinto every attached inbound. Its only guard,addressesFitAmneziaWGInbound(client_crud.go:757-760), returnstrueunconditionally whenib.Protocol != model.AmneziaWG, and coversAllowedIPsonly — neverPrivateKey/PublicKey/PreSharedKey. Triggered whenever a client is attached to more than one WireGuard/AmneziaWG inbound and is saved from the client edit form, which sends one shared field set (frontend/src/pages/clients/ClientFormModal.tsx:695-719) becauseallowedIPsByInboundis only built when a wg AND an awg inbound are both attached (ClientFormModal.tsx:701) and even then names only the first of each (ClientFormModal.tsx:218-219). The partial AmneziaWG-only guard arrived ineffcccce("feat(amneziawg): add native AmneziaWG protocol support (#6105)", first tagged in v3.7.0); the broadcast loop it partially guards predates it, going back to41645255.Already fixed: Still present on the default branch (
f727d04f, tagged v3.7.0). No commit or merged PR after v3.7.0 touches this path.Duplicate of: None. Related: #6346 (same reporter, read-side counterpart — Config section shows only the first config); Related: #6328 (the mixed wg+awg case the existing partial guard was written for).
Evidence:
client_crud.go:522} else if !addressesFitAmneziaWGInbound(clientForInbound.AllowedIPs, inbound) {;client_crud.go:758-759if ib.Protocol != model.AmneziaWG || len(addrs) == 0 { return true };client_inbound_apply.go:698-700if clients[0].PrivateKey == "" { clients[0].PrivateKey = old.PrivateKey };client_inbound_apply.go:791-793writesprivateKey/publicKey/allowedIPsinto the settings map;ClientFormModal.tsx:695-696unconditional key assignment;ClientFormModal.tsx:218-219first-match-only inbound resolution;model.go:926-929singlewg_*column per field onClientRecord;client_update_allowedips_test.go:60covers only the one-wg-plus-one-awg pair;hooks/useClients.ts:349posts to/panel/api/clients/update/:emailwith noinboundIdsquery.Not determined: How your four peers came to hold distinct key pairs in the first place — the panel's own
Attachpath (client_crud.go:809-841) carries the record's single stored keypair into each new inbound, so distinct keys imply the inbounds were seeded independently on each node and merged bySyncInbound. This does not change the verdict; it only affects how many existing deployments already have per-peer keys left to lose. Reading the four inbounds'settingsJSON rows before and after one save would settle it exactly.Suggested fix: Widen the
client_crud.go:522guard so a shared field set is never broadcast to an inbound it was not loaded from — for WireGuard as well as AmneziaWG, and forPrivateKey/PublicKey/PreSharedKeyas well asAllowedIPs— lettingUpdateInboundClient's existing empty-field carry-forward preserve each peer's own values. The per-inbound editing UI the reporter asks for is a larger, separate change; the guard alone stops the data loss.@MHSanaei — confirmed High-severity bug, silently and irrecoverably overwrites per-peer WireGuard/AmneziaWG key material on a routine client save.
This reply was generated automatically; a maintainer may follow up.