mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6965] [MERGED] fix(amneziawg): validate peer subnets before enabling kernel mode #6548
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#6548
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/6965
Author: @Toximiner
Created: 10/26/2026
Status: ✅ Merged
Merged: 11/3/2026
Merged by: @MHSanaei
Base:
main← Head:fix/awg-kernel-peer-subnets📝 Commits (4)
2b3907efix(amneziawg): reject peers outside kernel interface subnets4d7680ffix(amneziawg): preserve reconciliation for legacy peer subnets8bf2424fix: preserve legacy AWG client recovery operationsa46666bMerge remote-tracking branch 'origin/main' into pr/6965📊 Changes
9 files changed (+286 additions, -9 deletions)
View changed files
📝
internal/amneziawgkern/config.go(+43 -0)📝
internal/amneziawgkern/config_test.go(+28 -0)📝
internal/amneziawgkern/manager_test.go(+33 -0)📝
internal/amneziawgkern/preflight.go(+1 -1)📝
internal/web/service/client_crud.go(+2 -2)📝
internal/web/service/client_inbound_apply.go(+38 -5)📝
internal/web/service/inbound_amneziawg.go(+17 -1)📝
internal/web/service/inbound_amneziawg_test.go(+40 -0)📝
internal/web/service/kernel_client_guard_test.go(+84 -0)📄 Description
Summary
Reject enabling or editing an active AmneziaWG kernel-mode inbound when its peers' IPv4 AllowedIPs fall outside the configured interface subnets. Report the configuration mismatch before persisting an unroutable change.
Why
An inbound restored from a backup can have server subnet
10.9.1.0/24while its clients still use10.8.1.x/32. The embedded backend can serve this configuration, but switching to kernel mode currently succeeds and installs an interface route and masquerade rule for10.9.1.0/24only. Clients can complete the handshake while internet access fails.Reproduction on v3.11.0:
10.9.1.0/24and an enabled client at10.8.1.2/32.This change reports the offending peer, AllowedIPs and server subnet instead. The same validation covers active client creation, enabling a disabled client, newly added client addresses, and kernel-mode preflight. Both save paths reuse the subnet derivation already used by the client address allocator. Embedded configurations remain editable, and a broken inbound can still be disabled.
Runtime reconciliation deliberately preserves the previous behavior for inconsistent rows already in the database. A legacy stray peer must not prevent correctly addressed peers from starting after a restart, nor freeze updates that revoke other peers after quota or expiry checks. Such a peer still needs its address/server subnet corrected; this PR prevents new invalid interactive changes rather than automatically repairing restored data or changing renewal policy. Single-client updates retain existing addresses on active legacy peers, so metadata edits, renewals, renames and disabling remain possible. Disabled clients and disabled inbounds do not undergo the new subnet check; enabling them validates the active addresses again.
The original source of an inconsistent backup is not established by this PR. Client addresses and keys are not automatically rewritten.
Type of change
Areas affected
How was this tested?
Using Go 1.27.3:
go build ./...go test -p=1 -shuffle=1793050079268997904 -count=1 ./...go test -race -shuffle=on -count=1 ./internal/amneziawgkerngo test -race -shuffle=on -count=1 ./internal/web/service -run '^TestKernelAWG'The frontend embed directory was stubbed with
internal/web/dist/.gitkeep, matching the repository's Go CI setup. An initial parallel package run hit a TUIC test's local-port collision; the service package passed when replayed with the same shuffle seed.Breaking changes
Interactive saves of enabled kernel-mode inbounds, active client creation, client activation and newly added active-client addresses now reject IPv4 AllowedIPs outside every interface subnet with an actionable error. Existing active legacy addresses remain editable without being rewritten; disabling and renewal remain available. Align the server subnet and client addresses before enabling kernel mode. Legacy runtime reconciliation is unchanged. No database migration or client key rotation is performed.
Checklist
go build ./...and the Go test suite pass locally.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
[PR #6965] fix(amneziawg): validate peer subnets before enabling kernel modeto [PR #6965] [MERGED] fix(amneziawg): validate peer subnets before enabling kernel mode