mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6540] [MERGED] fix(amneziawg): stop a disabled inbound's relay slot from being taken #6340
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#6340
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/6540
Author: @BlindMaster24
Created: 9/15/2026
Status: ✅ Merged
Merged: 9/15/2026
Merged by: @BlindMaster24
Base:
main← Head:fix/amneziawg-disabled-relay-slot📝 Commits (3)
538232ctest(amneziawg): pin that a disabled row still owns its relay slot2553889fix(amneziawg): count a disabled inbound as owning its relay slotdbb04d2test(amneziawg): drop the disabled-row case that asserts the reversed rule📊 Changes
3 files changed (+31 additions, -25 deletions)
View changed files
📝
internal/web/service/inbound_amneziawg_relay_window_test.go(+27 -0)📝
internal/web/service/port_conflict.go(+4 -2)📝
internal/web/service/port_conflict_test.go(+0 -23)📄 Description
Summary
A local AmneziaWG inbound owns the loopback relay port its id derives for as long as the row exists — but the forward port check only counted its enabled rows as owners. An ordinary inbound could therefore be saved onto that port while the AmneziaWG row was off, and turning that row back on then put two inbounds on
127.0.0.1:65101, which makes Xray refuse its whole config and takes every other protocol on the host down with it.Found as a pre-existing MEDIUM during the review of #6539; this is the second half of the same invariant that change wrote down in the other direction.
Why it happens
checkAmneziawgnetSocksConflictfilters its candidates withenable = true(internal/web/service/port_conflict.go:290), so a disabled AmneziaWG row is invisible when a new inbound's configured port is validated. Nothing else covers the gap: the relay is not a database row, so the generalport = ?query cannot see it, andSetInboundEnable(internal/web/service/inbound.go:1566-1588) flips the column inside a transaction that runs no port check at all.Reproduces entirely through the panel:
#1exists and is toggled off.injectAmneziawgnetSocksskips it (internal/web/service/xray.go:739requiresinbound.Enable), so no relay is in the generated config — but the row still owns slot65101.65101. The forward check drops the disabled row, the DB query finds nothing, the save succeeds.#1is toggled back on. No port check runs.127.0.0.1:65101; Xray fails the second bind and refuses the entire config.Why this rule, and not a check on the enable path
Two designs close that sequence, and the review asked for the choice to be deliberate rather than inherited from a shared helper:
SetInboundEnablevalidates the relay port when it switches the row on.A is taken because the rule already exists in three of the four AmneziaWG checks in this file, including
checkAmneziawgnetSocksRelayCollision, which shipped in #6539 and treats a disabled owner as an owner for exactly the reason that decides this: re-enabling runs no port check. B would make those three agree only by relaxing the merged one, and it moves a resource conflict onto a toggle that users flip as a routine on/off switch, where a refusal is far more surprising than at save time. The cost of A is the narrow case in Breaking changes below, which B would avoid.The change
One predicate: the forward check now counts every local AmneziaWG row, disabled ones included.
Type of change
Areas affected
How was this tested?
TestCheckPortConflict_DisabledAmneziawgStillOwnsItsRelaySlot— an AmneziaWG inbound is created disabled, and an ordinary inbound is then validated on that row's derived relay port; the save must be refused with the owner named.It fails without the fix, on a test-only head whose CI run failed on exactly that one test:
TestCheckPortConflict_AmneziawgnetSocksRelayIgnoredWhenDisabled(internal/web/service/port_conflict_test.go) is deleted by this PR. It asserted the rule this change reverses, and it never reached the predicate it named: its fixture seedsSettings: {}, whichamneziawg.InstanceFromInboundrejects onparsed.Server == nil(internal/amneziawg/instance.go:32) one statement before theenablecolumn is looked at, so it passed with or without the filter. Leaving it would have had the package documenting both rules for the same operator state with nothing failing to flag the contradiction.go build ./...and the test suite pass locally — cannot run on this machine (no C toolchain:CGO_ENABLED=0, sogo-sqlite3is its stub). The DB-backed tests compile here and CI exercises them.npm run lint,npm run typecheck, andnpm run buildpass. — N/Adocs/, the translations and the frontend.Breaking changes
No schema change, no migration, and no row's stored data moves. Xray's generated config is unchanged for every setup that starts today, apart from the case below.
The one behaviour change: a database that already holds a disabled AmneziaWG row and an ordinary inbound configured on that row's derived relay port (
65101–65535) can no longer save that ordinary inbound while it keeps that port — not just a port change, but any save through that inbound's own update path, such as a remark or a TLS setting (adding a client to it goes through a different path that runs no port check). That state exists today and its config starts, because the disabled row injects no relay. The escape is the port change itself, which succeeds: the check compares the incoming port, so moving that inbound off the relay slot clears the refusal, and deleting the AmneziaWG row clears it too. Ports in65101–65535are panel-internal and never suggested, so reaching this state takes a deliberate choice of a very high port; the state is also the only one in which the AmneziaWG row can never be switched on.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.