mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6367] [Bug]: AmneziaWG inbound ignores the "listen" field and always binds all addresses #4323
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#4323
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 @IvanSavoskin on GitHub (Aug 30, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6367
Describe the bug
An inbound with
protocol: amneziawgand a non-emptylistenvalue binds to all addressesinstead of the configured one. Inbounds backed by Xray honour
listennormally on the samepanel.
The panel stores the value correctly —
GET /panel/api/inbounds/get/:idreturns"listen": "SECONDARY_IP"— but the embedded device listens on the wildcard address.On a host with two public IPv4 addresses this is not cosmetic. Because the socket is bound
to the wildcard address, the source address of every reply is chosen by the routing table
instead of the address the request arrived on. Clients that connect to the secondary IP get
answers from the primary one, discard them, and never complete a handshake.
How to reproduce the problem
PRIMARY_IPas the primaryaddress and the default route source,
SECONDARY_IPas an additional/32).protocol: amneziawg,port: 1235,listen: SECONDARY_IP.ss -lunp | grep 1235— the socket is bound to0.0.0.0and[::], not toSECONDARY_IP.SECONDARY_IP:1235and capture traffic on the server.Expected behavior
An AmneziaWG inbound with a non-empty
listenbinds only to that address, the same wayXray-backed inbounds do, and replies leave from the address the client connected to.
If per-address binding is not supported by the embedded device, the field should be rejected
on save or documented as ignored for this protocol, so that multi-IP setups do not fail
silently.
Actual behavior
The socket is bound to all addresses, replies are sourced from the primary IP, and the
handshake never completes. The client retries every ~5 seconds indefinitely. Nothing is
logged by the panel.
Workaround that makes the second inbound usable — note that
SNATalone is not enough,because the incoming packet has already created a conntrack entry whose reply tuple is
exactly what
SNATproduces, so the translated packet clashes on insert and is droppedsilently. The incoming flow has to be left untracked as well:
Relevant logs
Screenshots
No response
3x-ui version
3.7.0
Xray-core version
26.7.28
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 24.04 LTS, x86_64
Which parts of the panel are affected?
Xray config generation
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 30, 2026):
Confirmed — the panel never passes an AmneziaWG inbound's
listenvalue into the embedded device at all, so the wildcard bind you captured withssis exactly what the current code produces. Your reading of the symptom is right; the only correction is the location: AmneziaWG inbounds are deliberately excluded from the generated Xray config, so this is not in "Xray config generation".Here is the whole path the value would have to travel, and where it stops:
InstanceFromInboundbuilds the desired instance from the inbound row and copies only the port —ib.Listenis never read:amneziawg.Instance(internal/amneziawg/types.go:73-124) has no bind-address field of any kind —ListenPort intattypes.go:77is the only listener-related member, so there is nothing for the runtime to carry even if it wanted to.The one socket-creating call site takes no address:
and the UAPI config the device is configured with emits only a port:
Desired{}construction sites (internal/web/job/amneziawg_job.go:39,internal/web/runtime/local.go:63and:196) passInstanceplusDeviceOptions, andDeviceOptions(device.go:30-68) holds only obfuscation/timing fields.grep -rn "\.Listen" internal/amneziawg internal/amneziawgnetreturns nothing outside tests.For contrast, both of the other listener families do honour it. Xray-backed inbounds (including the native WireGuard protocol) get it written into the config:
and the other non-Xray sidecar, MTProto, maps the same field onto its child process (
internal/mtproto/manager.go:220Listen: ib.Listen, consumed bybindTo()atmanager.go:74-80). AmneziaWG is the only protocol that drops it silently — andinternal/web/service/xray.go:177(if inbound.Protocol == model.MTProto || inbound.Protocol == model.AmneziaWG { continue }) is why nothing further downstream ever sees it either.Two things make the silence worse than a plain unimplemented field:
listenis used as the advertised address elsewhere:internal/sub/service.go:1298-1316puts it into the candidate list (and puts it first under thelistenshare-address strategy), so generated client configs getEndpoint = SECONDARY_IP:1235for a server that never sources replies from that address — precisely the asymmetry in yourtcpdump.listenvalues as non-conflicting (internal/web/service/port_conflict.go:94-99:return a == b), which for AmneziaWG is not true, since both bind the wildcard. I did not test that pairing, so treat the consequence as an inference rather than a confirmed second defect.The per-client port-forward listeners have the same gap by construction —
internal/amneziawgnet/portfwd.go:288andportfwd_udp.go:49both format":%d".Your
iptablesworkaround is sound and is currently the only way to pin the reply source for this protocol; nothing in the panel can do it for you today.Verdict: Confirmed bug
Severity: Medium
Confidence: High
Root cause:
InstanceFromInboundininternal/amneziawg/instance.go:61-66copiesib.PortintoInstance.ListenPortand never readsib.Listen;amneziawg.Instance(internal/amneziawg/types.go:73-124) has no bind-address field, so the single socket-creating call siteinternal/amneziawgnet/device.go:139usesawgconn.NewDefaultBind()andbuildUAPIConfig(device.go:197) emits onlylisten_port. Triggered by any AmneziaWG inbound with a non-emptylisten; no input reaches a per-address bind. Introduced byeffcccce"feat(amneziawg): add native AmneziaWG protocol support (#6105)" (2026-08-24), the only commit that has ever touchedinternal/amneziawgnet/device.go.Already fixed: Still present on the default branch (HEAD
f727d04f, v3.7.0 — the first release containingeffcccce, pergit tag --contains).Duplicate of: None. Related: #6323 (AmneziaWG session dies after handshake) shares neither the bind path nor the root cause, so it is not the same defect.
Evidence:
internal/amneziawg/instance.go:65ListenPort: ib.Port,;internal/amneziawg/types.go:77ListenPort int;internal/amneziawgnet/device.go:139dev := device.NewDevice(tun, awgconn.NewDefaultBind(), logger);internal/amneziawgnet/device.go:197fmt.Fprintf(&b, "listen_port=%d\n", inst.ListenPort);internal/database/model/model.go:344listen := i.Listen(Xray path, for contrast);internal/mtproto/manager.go:220Listen: ib.Listen(MTProto sidecar, for contrast);internal/web/service/xray.go:177excludes AmneziaWG from the Xray config;internal/web/service/port_conflict.go:94-99listenOverlaps;internal/sub/service.go:1306-1313. No comment or test anywhere ininternal/amneziawg/internal/amneziawgnetdocuments or pins the wildcard bind as intended, and the frontend offers the field for every protocol without a caveat (frontend/src/pages/inbounds/form/InboundFormModal.tsx:639-644).Not determined: Whether
amneziawg-gov3.1.20260814's default bind implements sticky source addresses (IP_PKTINFO), which would decide whether a wildcard-bound socket could ever reply from the right address — I could not read the dependency's source in this environment, and your capture already shows it does not in practice. Readingconn/bind_std.goin that module would settle it; it does not change the verdict, since the panel supplies no address either way.Suggested fix: carry the inbound's
listenonamneziawg.Instanceand open the device with a bind pinned to it instead ofawgconn.NewDefaultBind()atinternal/amneziawgnet/device.go:139, adding it toaddressFingerprint(internal/amneziawgnet/manager.go:258) so an edit rebuilds the Device rather than trying to hot-apply it. If a per-address bind is not wanted for this protocol, the cheaper alternative is to reject a non-emptylistenformodel.AmneziaWGat save time so it fails loudly instead of silently.This reply was generated automatically; a maintainer may follow up.