[PR #6344] [MERGED] fix: preserve per-inbound WireGuard peer addresses #6226

Closed
opened 2026-11-02 04:07:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6344
Author: @mvanhorn
Created: 8/28/2026
Status: ✅ Merged
Merged: 9/2/2026
Merged by: @MHSanaei

Base: main ← Head: fix/6328-preserve-wireguard-peer-addresses


📝 Commits (1)

  • b455706 fix: preserve per-inbound WireGuard peer addresses

📊 Changes

2 files changed (+100 additions, -0 deletions)

View changed files

📝 internal/web/service/xray.go (+14 -0)
📝 internal/web/service/xray_wireguard_config_test.go (+86 -0)

📄 Description

Summary

WireGuard peers were built from the shared per-email client record, so a client present on both a WireGuard and an AmneziaWG inbound got one tunnel's allowedIPs and preSharedKey on both. This reads the per-inbound client settings and uses the inbound's own entry when one exists for that email.

Why

Closes #6328

Clients are stored once per email in the client table. GetXrayConfig built each WireGuard peer from that shared record, so the per-inbound values were lost whenever the same email appeared on two WireGuard-family inbounds. The second tunnel's peer was then emitted with the first tunnel's address, which breaks routing for that client.

The inbound already carries its own client settings; they were simply not consulted on the WireGuard path.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

Added TestGetXrayConfigWireGuardUsesInboundLocalTunnelFields, which seeds one email on both a WG inbound (10.0.0.5/32, wg-psk) and an AWG inbound (10.8.1.5/32, awg-psk) and asserts each inbound's peer keeps its own address and pre-shared key.

$ go build ./...
$ go test ./internal/web/service/... -run 'WireGuard|Wireguard|WG'
ok  	github.com/mhsanaei/3x-ui/v3/internal/web/service	2.430s
ok  	github.com/mhsanaei/3x-ui/v3/internal/web/service/integration	2.198s

The test pins the bug rather than merely covering the path. Reverting only internal/web/service/xray.go and keeping the test:

--- FAIL: TestGetXrayConfigWireGuardUsesInboundLocalTunnelFields
    xray_wireguard_config_test.go:210: WireGuard peer allowedIPs = [10.8.1.5/32], want [10.0.0.5/32]

That is the reported symptom exactly: the AWG tunnel's address on the WG peer.

Not tested: no run against a live Xray instance with two active tunnels. The assertion is on generated config, not on observed traffic.

Screenshots / recordings

N/A. Backend config generation, no UI change.

Breaking changes

None. Behaviour only changes where an inbound carries its own client entry for that email; when it does not, the existing shared-record values are used exactly as before.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

Frontend checks are unchecked because there are no frontend changes. Docs are unchecked because the corrected behaviour is what the panel already documents; nothing user-facing changed.

AI assistance disclosure

  • Type of assistance: drafting the code change, the test, and this description.
  • Scope: internal/web/service/xray.go and internal/web/service/xray_wireguard_config_test.go only.
  • Tools: OpenAI Codex for the implementation, Anthropic Claude for review and this write-up.
  • Level of modification: the build, the test run, and the revert-the-fix check quoted above were run locally and their real output is reproduced here.

AI was used for assistance.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6344 **Author:** [@mvanhorn](https://github.com/mvanhorn) **Created:** 8/28/2026 **Status:** ✅ Merged **Merged:** 9/2/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/6328-preserve-wireguard-peer-addresses` --- ### 📝 Commits (1) - [`b455706`](https://github.com/MHSanaei/3x-ui/commit/b455706ad2a1a7469f435a30b75f253cb62526df) fix: preserve per-inbound WireGuard peer addresses ### 📊 Changes **2 files changed** (+100 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/xray.go` (+14 -0) 📝 `internal/web/service/xray_wireguard_config_test.go` (+86 -0) </details> ### 📄 Description ## Summary WireGuard peers were built from the shared per-email client record, so a client present on both a WireGuard and an AmneziaWG inbound got one tunnel's `allowedIPs` and `preSharedKey` on both. This reads the per-inbound client settings and uses the inbound's own entry when one exists for that email. ## Why Closes #6328 Clients are stored once per email in the client table. `GetXrayConfig` built each WireGuard peer from that shared record, so the per-inbound values were lost whenever the same email appeared on two WireGuard-family inbounds. The second tunnel's peer was then emitted with the first tunnel's address, which breaks routing for that client. The inbound already carries its own client settings; they were simply not consulted on the WireGuard path. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [x] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? Added `TestGetXrayConfigWireGuardUsesInboundLocalTunnelFields`, which seeds one email on both a WG inbound (`10.0.0.5/32`, `wg-psk`) and an AWG inbound (`10.8.1.5/32`, `awg-psk`) and asserts each inbound's peer keeps its own address and pre-shared key. ``` $ go build ./... $ go test ./internal/web/service/... -run 'WireGuard|Wireguard|WG' ok github.com/mhsanaei/3x-ui/v3/internal/web/service 2.430s ok github.com/mhsanaei/3x-ui/v3/internal/web/service/integration 2.198s ``` The test pins the bug rather than merely covering the path. Reverting only `internal/web/service/xray.go` and keeping the test: ``` --- FAIL: TestGetXrayConfigWireGuardUsesInboundLocalTunnelFields xray_wireguard_config_test.go:210: WireGuard peer allowedIPs = [10.8.1.5/32], want [10.0.0.5/32] ``` That is the reported symptom exactly: the AWG tunnel's address on the WG peer. Not tested: no run against a live Xray instance with two active tunnels. The assertion is on generated config, not on observed traffic. ## Screenshots / recordings N/A. Backend config generation, no UI change. ## Breaking changes None. Behaviour only changes where an inbound carries its own client entry for that email; when it does not, the existing shared-record values are used exactly as before. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. Frontend checks are unchecked because there are no frontend changes. Docs are unchecked because the corrected behaviour is what the panel already documents; nothing user-facing changed. ## AI assistance disclosure - Type of assistance: drafting the code change, the test, and this description. - Scope: `internal/web/service/xray.go` and `internal/web/service/xray_wireguard_config_test.go` only. - Tools: OpenAI Codex for the implementation, Anthropic Claude for review and this write-up. - Level of modification: the build, the test run, and the revert-the-fix check quoted above were run locally and their real output is reproduced here. AI was used for assistance. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:15 +07:00
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#6226
No description provided.