mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #7090] fix(amneziawg): check forwarded ports against the port the panel listens on #6644
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#6644
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/7090
Author: @Dv2Corn
Created: 11/6/2026
Status: 🔄 Open
Base:
main← Head:fix/awg-forward-xui-port📝 Commits (1)
824e113fix(amneziawg): check forwarded ports against the port the panel listens on📊 Changes
5 files changed (+57 additions, -4 deletions)
View changed files
📝
internal/web/service/inbound_amneziawg.go(+1 -1)📝
internal/web/service/inbound_amneziawg_test.go(+15 -0)📝
internal/web/service/setting.go(+9 -0)➕
internal/web/service/setting_listen_port_test.go(+30 -0)📝
internal/web/web.go(+2 -3)📄 Description
Summary
The AmneziaWG port-forward conflict check now compares a client's forwarded ports with the port the panel really listens on,
XUI_PORTwhen it is set, instead of the storedwebPort. TheXUI_PORT-over-webPortrule moves into one helper,SettingService.GetListenPort, which the web server and the check both use.Why
The web server listens on
XUI_PORTwhen it is set and valid, and on the storedwebPortotherwise (web.go#L592-L604). The conflict check that guards AmneziaWGforwardedPortsreads only the storedwebPort(inbound_amneziawg.go#L379, used at #L427).With
XUI_PORTset (the Docker setup documentsXUI_PORT: "8080"with the same port published), a client can be saved with a forward on the real panel port, for example8080. The check passes, because the storedwebPortis still2053, but the forward listener can never bind, since the panel already holds that port. Meanwhile a forward on2053, a port nothing listens on, is refused.What changes:
SettingService.GetListenPort(): a validXUI_PORTwins, otherwise the storedwebPort. That is the same rule the web server applied inline, so an invalidXUI_PORTis still ignored with the existing warning.Server.starttakes its port fromGetListenPort(); it keeps the warning/info log lines.loadPortConflictContextusesGetListenPort().Type of change
Areas affected
How was this tested?
New tests:
TestCheckForwardedPortsConflict_CollidesWithXUIPortininternal/web/service/inbound_amneziawg_test.go:XUI_PORT=8443on a fresh database (storedwebPortis the default2053); a forward on8443must be reported as a collision with the panel. Onmainit fails withexpected a collision naming the port XUI_PORT makes the panel listen on, got ""; with the fix it passes.TestGetListenPortininternal/web/service/setting_listen_port_test.go:XUI_PORTunset gives2053,8443gives8443,abcand70000fall back to2053.The existing
TestCheckForwardedPortsConflict_*tests, includingCollidesWithPanelPortwithoutXUI_PORT, still pass.Run with Go 1.27.3 and the
internal/web/diststub the CI uses:go build ./...,go vet ./...andgofmt -lare clean.go test -shuffle=on -count=1 ./internal/web/service ./internal/webpasses.go test -race -shuffle=on -count=1 ./internal/web/servicepasses.Screenshots / recordings
N/A
Breaking changes
None. Without
XUI_PORTnothing changes. WithXUI_PORTset, a new AmneziaWG forward on that port is now refused, and a forward on the storedwebPortis no longer refused. Every save of an AmneziaWG inbound re-checks all its clients, so an inbound that already has a client forwarding theXUI_PORTport is refused on its next save, with an error naming that client and the panel port, until the forward is changed. That forward could not bind anyway.Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.