[GH-ISSUE #6372] [Bug]: Editing a client overwrites all WireGuard/AmneziaWG peers with one config, breaking tunnels on the other nodes #4325

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

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

  1. Main panel with 4 remote nodes attached.
  2. Create WireGuard or AmneziaWG inbounds on each node, each with its own subnet
    (e.g. 10.10.151.0/24, 10.10.152.0/24, ...).
  3. Add one client, e.g. NSK-RT-01, to the inbounds on all four nodes. Each peer gets its
    own key pair and address, and all four tunnels work.
  4. Open the client's properties, change anything, save.
  5. Inspect the configs of all four inbounds (subscription page shows them all): every
    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

  • 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 @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 1. Main panel with 4 remote nodes attached. 2. Create WireGuard or AmneziaWG inbounds on each node, each with its own subnet (e.g. 10.10.151.0/24, 10.10.152.0/24, ...). 3. Add one client, e.g. NSK-RT-01, to the inbounds on all four nodes. Each peer gets its own key pair and address, and all four tunnels work. 4. Open the client's properties, change anything, save. 5. Inspect the configs of all four inbounds (subscription page shows them all): every 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 ```shell ``` ### 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 - [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:50 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@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.

resolveTunnelAllowedIPsByInbound picks the first attached inbound of each protocol, and nothing else (frontend/src/pages/clients/ClientFormModal.tsx:218):

const wgId = attachedInboundIds.find((id) => wireguardInboundIds.has(id));
const awgId = attachedInboundIds.find((id) => amneziawgInboundIds.has(id));

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):

if (showWireguard && showAmneziawg) {

Four WireGuard inbounds means showAmneziawg === false, so allowedIPsByInbound is never populated and the code falls through to the single broadcast value at ClientFormModal.tsx:717-719. The keys are unconditional (ClientFormModal.tsx:695-696):

clientPayload.privateKey = values.wgPrivateKey;
clientPayload.publicKey = values.wgPublicKey;

Backend — the only guard is AmneziaWG-only, and it only covers the address.

ClientService.Update loops over every attached inbound and copies the one updated client into each (internal/web/service/client_crud.go:519-533). The protective branch is addressesFitAmneziaWGInbound, and its first statement is (client_crud.go:758-760):

if ib.Protocol != model.AmneziaWG || len(addrs) == 0 {
    return true
}

For model.WireGuard it returns true unconditionally, so clientForInbound.AllowedIPs is never cleared and inbound #1's address is written verbatim into inbounds #2–#4. UpdateInboundClient then accepts it, because its carry-forward only fires when the incoming field is empty (internal/web/service/client_inbound_apply.go:696-703):

if clients[0].PrivateKey == "" {
    clients[0].PrivateKey = old.PrivateKey
}

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 — so 10.10.151.5/32 lands in a 10.10.152.0/24 inbound without complaint. The values are stamped into the settings JSON at client_inbound_apply.go:790-799.

So, precisely:

your topology address private/public key
4× WireGuard inbounds overwritten on 3 of 4 overwritten on all 4
4× AmneziaWG inbounds, distinct subnets preserved (the addressesFitAmneziaWGInbound guard fires) overwritten on all 4

There is no privateKeyByInbound counterpart to allowedIPsByInbound anywhere in the tree, which is why the key broadcast survives even where the address guard works. model.ClientRecord itself 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 own settings JSON, 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 inboundIds query parameter that scopes the update to specific inbounds (internal/web/controller/client.go:210-211 → the filter at client_crud.go:414-426). The panel UI never sends it, but you can:

curl -X POST 'https://<panel>/<base-path>/panel/api/clients/update/NSK-RT-01?inboundIds=7' \
  -H 'Content-Type: application/json' \
  -d '{"email":"NSK-RT-01","enable":true,"privateKey":"<key for inbound 7>","allowedIPs":["10.10.152.5/32"], ... }'

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 settings JSON in /etc/x-ui/x-ui.db carries 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.Update at internal/web/service/client_crud.go:519-533 copies one model.Client into every attached inbound. Its only guard, addressesFitAmneziaWGInbound (client_crud.go:757-760), returns true unconditionally when ib.Protocol != model.AmneziaWG, and covers AllowedIPs only — never PrivateKey/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) because allowedIPsByInbound is 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 in effcccce ("feat(amneziawg): add native AmneziaWG protocol support (#6105)", first tagged in v3.7.0); the broadcast loop it partially guards predates it, going back to 41645255.
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-759 if ib.Protocol != model.AmneziaWG || len(addrs) == 0 { return true }; client_inbound_apply.go:698-700 if clients[0].PrivateKey == "" { clients[0].PrivateKey = old.PrivateKey }; client_inbound_apply.go:791-793 writes privateKey/publicKey/allowedIPs into the settings map; ClientFormModal.tsx:695-696 unconditional key assignment; ClientFormModal.tsx:218-219 first-match-only inbound resolution; model.go:926-929 single wg_* column per field on ClientRecord; client_update_allowedips_test.go:60 covers only the one-wg-plus-one-awg pair; hooks/useClients.ts:349 posts to /panel/api/clients/update/:email with no inboundIds query.
Not determined: How your four peers came to hold distinct key pairs in the first place — the panel's own Attach path (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 by SyncInbound. 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' settings JSON rows before and after one save would settle it exactly.

Suggested fix: Widen the client_crud.go:522 guard so a shared field set is never broadcast to an inbound it was not loaded from — for WireGuard as well as AmneziaWG, and for PrivateKey/PublicKey/PreSharedKey as well as AllowedIPs — letting UpdateInboundClient'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.

<!-- gh-comment-id:5475719770 --> @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.** `resolveTunnelAllowedIPsByInbound` picks the *first* attached inbound of each protocol, and nothing else (`frontend/src/pages/clients/ClientFormModal.tsx:218`): ```ts const wgId = attachedInboundIds.find((id) => wireguardInboundIds.has(id)); const awgId = attachedInboundIds.find((id) => amneziawgInboundIds.has(id)); ``` 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`): ```ts if (showWireguard && showAmneziawg) { ``` Four WireGuard inbounds means `showAmneziawg === false`, so `allowedIPsByInbound` is never populated and the code falls through to the single broadcast value at `ClientFormModal.tsx:717-719`. The keys are unconditional (`ClientFormModal.tsx:695-696`): ```ts clientPayload.privateKey = values.wgPrivateKey; clientPayload.publicKey = values.wgPublicKey; ``` **Backend — the only guard is AmneziaWG-only, and it only covers the address.** `ClientService.Update` loops over every attached inbound and copies the one `updated` client into each (`internal/web/service/client_crud.go:519-533`). The protective branch is `addressesFitAmneziaWGInbound`, and its first statement is (`client_crud.go:758-760`): ```go if ib.Protocol != model.AmneziaWG || len(addrs) == 0 { return true } ``` For `model.WireGuard` it returns `true` unconditionally, so `clientForInbound.AllowedIPs` is never cleared and inbound #1's address is written verbatim into inbounds #2–#4. `UpdateInboundClient` then accepts it, because its carry-forward only fires when the incoming field is empty (`internal/web/service/client_inbound_apply.go:696-703`): ```go if clients[0].PrivateKey == "" { clients[0].PrivateKey = old.PrivateKey } ``` 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 — so `10.10.151.5/32` lands in a `10.10.152.0/24` inbound without complaint. The values are stamped into the settings JSON at `client_inbound_apply.go:790-799`. **So, precisely:** | your topology | address | private/public key | | --- | --- | --- | | 4× **WireGuard** inbounds | **overwritten** on 3 of 4 | **overwritten** on all 4 | | 4× **AmneziaWG** inbounds, distinct subnets | preserved (the `addressesFitAmneziaWGInbound` guard fires) | **overwritten** on all 4 | There is no `privateKeyByInbound` counterpart to `allowedIPsByInbound` anywhere in the tree, which is why the key broadcast survives even where the address guard works. `model.ClientRecord` itself 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 own `settings` JSON, 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 `inboundIds` query parameter that scopes the update to specific inbounds (`internal/web/controller/client.go:210-211` → the filter at `client_crud.go:414-426`). The panel UI never sends it, but you can: ```bash curl -X POST 'https://<panel>/<base-path>/panel/api/clients/update/NSK-RT-01?inboundIds=7' \ -H 'Content-Type: application/json' \ -d '{"email":"NSK-RT-01","enable":true,"privateKey":"<key for inbound 7>","allowedIPs":["10.10.152.5/32"], ... }' ``` 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 `settings` JSON in `/etc/x-ui/x-ui.db` carries 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.Update` at `internal/web/service/client_crud.go:519-533` copies one `model.Client` into every attached inbound. Its only guard, `addressesFitAmneziaWGInbound` (`client_crud.go:757-760`), returns `true` unconditionally when `ib.Protocol != model.AmneziaWG`, and covers `AllowedIPs` only — never `PrivateKey`/`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`) because `allowedIPsByInbound` is 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 in effcccce ("feat(amneziawg): add native AmneziaWG protocol support (#6105)", first tagged in v3.7.0); the broadcast loop it partially guards predates it, going back to 41645255. 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-759` `if ib.Protocol != model.AmneziaWG || len(addrs) == 0 { return true }`; `client_inbound_apply.go:698-700` `if clients[0].PrivateKey == "" { clients[0].PrivateKey = old.PrivateKey }`; `client_inbound_apply.go:791-793` writes `privateKey`/`publicKey`/`allowedIPs` into the settings map; `ClientFormModal.tsx:695-696` unconditional key assignment; `ClientFormModal.tsx:218-219` first-match-only inbound resolution; `model.go:926-929` single `wg_*` column per field on `ClientRecord`; `client_update_allowedips_test.go:60` covers only the one-wg-plus-one-awg pair; `hooks/useClients.ts:349` posts to `/panel/api/clients/update/:email` with no `inboundIds` query. Not determined: How your four peers came to hold *distinct* key pairs in the first place — the panel's own `Attach` path (`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 by `SyncInbound`. 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' `settings` JSON rows before and after one save would settle it exactly. Suggested fix: Widen the `client_crud.go:522` guard so a shared field set is never broadcast to an inbound it was not loaded from — for WireGuard as well as AmneziaWG, and for `PrivateKey`/`PublicKey`/`PreSharedKey` as well as `AllowedIPs` — letting `UpdateInboundClient`'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.* <!-- claude-issue:analyst -->
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#4325
No description provided.