mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6642] [MERGED] fix(amneziawg): bound S1-S3 by the receive buffer, reject overlapping H #6393
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#6393
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/6642
Author: @rudenko-ks
Created: 9/24/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @MHSanaei
Base:
main← Head:fix/amneziawg-obfuscation-bounds📝 Commits (4)
44d9c1cfix(amneziawg): bound S1-S3 by the receive buffer, reject overlapping H24147deMerge branch 'main' into fix/amneziawg-obfuscation-boundsa5bce06Merge remote-tracking branch 'origin/main' into pr-66427f38f51fix(amneziawg): bound only inbound padding by the iOS receive buffer📊 Changes
12 files changed (+189 additions, -35 deletions)
View changed files
📝
docs/content/docs/en/config/amneziawg.mdx(+3 -3)📝
frontend/src/pages/inbounds/form/protocols/amneziawg.tsx(+3 -3)📝
frontend/src/pages/xray/outbounds/protocols/amneziawg.tsx(+3 -3)📝
frontend/src/schemas/protocols/inbound/amneziawg.ts(+3 -3)📝
frontend/src/schemas/protocols/outbound/amneziawg.ts(+4 -3)📝
frontend/src/test/amneziawg-schema-cleared.test.ts(+22 -9)📝
internal/amneziawg/outbound_test.go(+22 -0)📝
internal/amneziawg/params.go(+53 -6)📝
internal/amneziawg/params_test.go(+63 -4)📝
internal/amneziawgnet/device_test.go(+11 -0)📝
internal/web/service/inbound_amneziawg.go(+1 -1)📝
internal/web/service/inbound_amneziawg_test.go(+1 -0)📄 Description
Summary
The native AmneziaWG validator (
internal/amneziawg/params.go), both Zod schemas, both forms and the docsdisagreed with amneziawg-go in three places. This PR makes them follow what the engine and its clients
actually enforce.
Amnezia Premium ships
s3=1045(s1=284 s2=659 s4=12, read from a live tunnel over UAPI).device, so the inbound saved fine and never came up.
The docs also stated two things the engine does not do. They said H
1–4"must not be used". They said"amneziawg-go rejects"
S1 + 56 = S2.1–2. S1–S3: the real bound is the smallest receive buffer
padding + size, where the sizes areMessageInitiationSize = 148,MessageResponseSize = 92andMessageCookieReplySize = 64:device/send.go,
device/noise-protocol.go.
[MaxMessageSize]bytebuffer, whereMaxMessageSize = MaxSegmentSize:device/pools.go,
device/constants.go.
MaxSegmentSizediffers by platform:RandomTrailersdoes not change these bounds. It only tops a packet up toDefaultUdpWindow = 500bytes(
randomTrailer()in send.go), so it never grows a message that is already larger.gives no reason for it. S4 ≤ 32 does have a reason (transport packets ride at full MTU) and is unchanged.
Such a config never worked for iOS clients. Linux/Android peers could still receive it.
S1 + 56 ≠ S2rule. Each maximum is valid on its own.3. H1–H4: reject overlap, allow 1–4
mergeWithDevicereturnsheaders must not overlap(device/uapi.go).
H1 must not overlap with others, and the same for H2–H4(src/netlink.c).
writeOptionalLineininternal/amneziawgnet/device.go), so the enginekeeps its default: WireGuard's own type
n(device.go,rang.FromUint32(MessageInitiationType, …)).The new check treats blank fields as that default. So
H1 = 3with a blank H3 is correctly rejected; theengine would refuse it.
default. With a HeaderProtectionKey (AWG 3+), the type field is encrypted on the wire (README, "Header
protection"). Amnezia Premium uses exactly
H1–H4 = 1/2/3/4together with a key. The docs now say that1–4 are valid, but that without a HeaderProtectionKey they leave the type field looking like plain WireGuard.
Docs corrections
S1 + 56 = S2". It does not: I checked amneziawg-go(
uapi.go,device.go), amneziawg-tools (config.c) and the kernel module (netlink.c), and a realIpcSetwith S1=30, S2=86 returns nil. The panel keeps the rule as a fingerprint guard (both packetswould have the same size on the wire), and the docs now say so.
Tests
internal/amneziawg/params_test.gocovers:100-200vs150-300,7vs7, and3vs blank-H3;1/2/3/4, all-blank and disjoint ranges are accepted.All of the new cases fail on the old code.
internal/amneziawgnet/device_test.goTestValidatedObfuscationAlwaysAppliesruns every set thevalidator accepts through a real amneziawg-go
IpcSet. New cases: H overlap, H1 equal to the blank-H3default, H 1–4, the S1/S3 and S2 bounds, and the full Amnezia Premium set. On the old validator it failed
twice with
IPC error -22: failed to merge with device: headers must not overlap.frontend/src/test/amneziawg-schema-cleared.test.ts: over-limit values are S1 1553, S2 1609, S3 1637;at-limit values are 1552, 1608, 1636. It fails with the old
.max(65535)/.max(64).go test ./internal/amneziawg/... ./internal/amneziawgnet/... ./internal/web/service/ ./internal/sub/—amneziawgnet under Linux; on Windows one of its UDP tests hangs for environment reasons, unrelated to
this change;
golangci-lint(GOOS=linux) on the touched packages: 0 issues;gofumpt,npm run typecheck,npm run lint: clean.Both branches were tested.
("started embedded interface");
passes traffic.
Not in this PR
duplicate was left out.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.