mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6407] AmneziaWG: empty client allowedIPs silently drops the whole inbound (no logs); server keys silently regenerate on update without explicit keys #4340
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#4340
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 @ARBlazeAG on GitHub (Sep 4, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6407
Environment
dev+38dd9bccand re-confirmed unchanged ondev+3ef06b70(2026-09-04), after upstream commitse95fe80f(fix(amneziawg): avoid manager lock inversion) andbd1c27b0(fix(amneziawg): H1-H4 generator + queue-depth throughput fixes) had already landed.POST /panel/api/inbounds/add,POST /panel/api/inbounds/update/{id}), not the web UI.Bug 1 — empty
allowedIPson a client silently drops the entire AmneziaWG instanceSteps to reproduce:
POST /panel/api/inbounds/addwithprotocol: "amneziawg", a validsettings.serverblock, and one client insettings.clientswithallowedIPs: [](empty array) and otherwise-valid keys.200 OK,"success": true, and the inbound is saved withenable: true.@every 10sAmneziaWGJobreconcile cycle.POST /panel/api/server/amneziawglogs/{count}→{"peers":[],"events":[],"running":false}.ss -ulnpon the host confirms no UDP socket was ever opened for that inbound's port.journalctl -u x-uihas zero lines mentioning the inbound, the interface, or any error — nothing to diagnose by.Expected: either the documented auto-assignment behaviour (
amneziawg.mdx: "Leave empty to auto-assign") actually happens server-side when creating/updating via the API, or the API rejects the emptyallowedIPswith a clear validation error at save time.Actual: the inbound is silently never brought up, with no error surfaced anywhere (API response, panel UI event log, or systemd journal).
Root cause (traced in source):
internal/amneziawg/instance.go,InstanceFromInbound:A client with empty
AllowedIPsis skipped frompeers; if that empties the whole peer list, the entire instance is dropped (ok=false). The caller,DesiredAmneziaWGInstancesininternal/web/service/inbound_amneziawg.go, does not log anything whenInstanceFromInboundreturnsfalse— so there's no trace at any log level explaining why an enabled inbound never starts.The "leave empty to auto-assign" behaviour documented in
amneziawg.mdxappears to only be implemented client-side in the React form (which fills the field before submit), not enforced or auto-filled server-side, so any non-UI API consumer silently loses the whole inbound.Suggested fix: either (a) implement the documented auto-assignment at the API/DB layer (next free host in the interface's subnet) so it's consistent regardless of caller, or (b) at minimum, log a
WarninginAmneziaWGJob.Run/DesiredAmneziaWGInstancesnaming the inbound id/tag that was skipped and why, so this doesn't look identical to "the reconcile job silently isn't running at all."Bug 2 — server keypair silently regenerates on
updateifserver.privateKey/publicKeyare omittedSteps to reproduce:
settings.server.publicKeyfrom the response).POST /panel/api/inbounds/update/{id}with asettings.serverobject that sets obfuscation params (jc/jmin/jmax/etc.) but omitsprivateKey/publicKeyentirely (only touching unrelated fields, e.g. togglingrandomTrailers).GET /panel/api/inbounds/get/{id}afterward.Expected: the existing server keypair is preserved, since the caller didn't ask to change it — matching how e.g. a VLESS client's UUID isn't rotated by an unrelated field edit.
Actual:
settings.server.publicKey/privateKeyare silently replaced with a brand-new keypair on everyupdatecall that doesn't explicitly re-send the current keys. This instantly invalidates every already-distributed client.conffor that inbound (wrong server public key), with no warning anywhere in the API response or logs.Suggested fix: on update, if
server.privateKey/publicKeyare empty/absent in the request body, load and keep the currently-stored values instead of generating a new pair. Only regenerate on an explicit "regenerate keys" action (mirroring how most other protocol fields already work — omitting a field on update shouldn't implicitly mean "replace with a fresh random value").Why this matters together
Both bugs share the same shape: a value that's fine to omit conceptually ("leave empty for default/auto/unchanged") is instead either fatal (bug 1) or destructively regenerated (bug 2), and neither failure mode is observable in logs. Anyone driving this API programmatically (or scripting bulk client management) will lose inbounds or break existing clients without any error to act on. Happy to provide the exact
curlreproduction sequences (payloads + responses) if useful.@github-actions[bot] commented on GitHub (Sep 4, 2026):
Both are real and both are still present at the tip (
3ef06b70), but your causal reading needs two corrections: the "leave empty to auto-assign" behaviour is implemented server-side — just on a different endpoint than the one you used — and the second problem is sharper than "keys are not preserved", becauseprivateKey-without-publicKeysilently blanks the server public key entirely.Bug 1 — empty
allowedIPsaccepted at save, then silently dropped at reconcileConfirmed. The save path for
/panel/api/inbounds/addand/update/{id}never checks that a client ended up with a usable address:normalizeWireguardAllowedIPsskips blanks and returns an empty slice with anilerror (internal/web/service/client_wireguard.go:136-140), so[]survives validation. Theninternal/amneziawg/instance.go:39skips the peer and:50-52drops the instance:DesiredAmneziaWGInstancesswallows thefalseatinternal/web/service/inbound_amneziawg.go:62-65(a barecontinue), andAmneziaWGJob.Runonly logs when the query fails (internal/web/job/amneziawg_job.go:32-35). Your "zero lines in the journal" observation matches the code exactly.Where your attribution is off: "Leave empty to auto-assign" is not from
amneziawg.mdx— it is the client-form hintpages.clients.amneziaWgAllowedIPsHint(internal/web/translation/en-US.json:874, rendered atfrontend/src/pages/clients/ClientFormModal.tsx:1253). And it is not frontend-only: the allocation runs in Go, indefaultAmneziaWGClients(internal/web/service/client_amneziawg.go:70-87), whose sole caller isAddInboundClient(internal/web/service/client_inbound_apply.go:409). That is the/panel/api/clients/addpath, documented atfrontend/src/pages/api-docs/endpoints.ts:1031-1036("Per-protocol secrets are generated server-side when omitted… plusallowedIPs: one free/32…").So the gap is specific: the whole-inbound endpoints do not run that allocator, and do not reject an empty
allowedIPseither.Workaround today — create the inbound with
"clients": [], then attach clients through the endpoint that does allocate:Or send an explicit
allowedIPs(e.g.["10.8.1.2/32"]) insideinbounds/add.Bug 2 — a
serverblock withoutprivateKeygets a brand-new random keypairConfirmed, with a caveat about why it happens, and one failure mode you did not hit that is worse.
fillAmneziaWGServerKeys(:152-160) overwrites bothPrivateKeyandPublicKey.UpdateInboundcalls the normalizer atinternal/web/service/inbound.go:1476, seventeen lines before it loadsoldInboundat:1493, so there is nothing stored to fall back to at that point. Nothing ininternal/web/controller/inbound.go:226-257merges either.The caveat:
/panel/api/inbounds/update/{id}is a documented whole-row replace, not a patch —frontend/src/pages/api-docs/endpoints.ts:63says so in a comment ("/inbounds/updatereplaces the whole row, so it takes the same payload as/add") and:296repeats it ("Replace an inbound's configuration. Body shape mirrors/add"). Your VLESS analogy does not hold: the same call withclientsomitted deletes every client and itsclient_trafficsrow (internal/web/service/inbound.go:1886-1901). Under those semantics, an omitted field being lost is the rule, not the exception.What is still a defect is that the lost keypair is replaced with a fresh random value instead of being rejected — the function's own comment (
:163-164) scopes that generation to "first save", but the code runs it identically on every update. And the gate is asymmetric in a way that is worse than what you reported: it fires only onPrivateKey == "", so a payload that sendsprivateKeybut omitspublicKeypasses validation untouched (ValidateConfigValueatinternal/amneziawg/params.go:281-288only rejects control characters) and leaves the server public key empty. Every.confbuilt from it then carries a blank line:There is no code anywhere that derives the server's
publicKeyfrom itsprivateKey—wgutil.PublicKeyFromPrivateis used for clients only (internal/web/service/client_amneziawg.go:63-69), whose comment states the opposite intent for peers: "Existing values are never overwritten, so an edit never rotates keys."Workaround today — read the inbound back and re-send its stored settings verbatim.
GET /panel/api/inbounds/get/{id}does not redactprivateKey(GetInboundDetail,internal/web/service/inbound.go:1332-1342, returns the raw row); the redaction you may have seen applies only toGET /panel/api/inbounds/options(inboundAmneziaWGServer,:437-439).Verdict: Confirmed bug
Severity: High
Confidence: High
Root cause: (1)
normalizeAmneziaWGSettings,internal/web/service/inbound_amneziawg.go:264-268— the per-client loop canonicalizesallowedIPsbut never rejects or allocates an empty one, sointernal/amneziawg/instance.go:39skips the peer and:50-52drops the whole instance, with the only two observers (inbound_amneziawg.go:62-65,internal/web/job/amneziawg_job.go:32-35) staying silent. Triggered by any/panel/api/inbounds/add|update/{id}payload whose amneziawg clients all carry an emptyallowedIPs; the panel UI never hits it because its client form posts to/panel/api/clients/add, which allocates viadefaultAmneziaWGClients(client_amneziawg.go:70-87). (2)normalizeAmneziaWGSettings,internal/web/service/inbound_amneziawg.go:196-200—fillAmneziaWGServerKeysis gated only onPrivateKey == ""and runs beforeUpdateInboundloads the stored row (inbound.go:1476vs:1493), so an update whoseserverblock omitsprivateKeymints a new keypair, and one that sendsprivateKeywithoutpublicKeyleaves the public key blank. Both introduced byeffcccce"feat(amneziawg): add native AmneziaWG protocol support (#6105)" (2026-08-24), the commit that created both files.Already fixed: Still present on the default branch (
3ef06b70).git log -- internal/amneziawg/instance.goand-- internal/web/service/inbound_amneziawg.goeach return onlyeffcccce; nothing has touched either path since.Duplicate of: None. Related: #6372 (WG/AWG peer data lost on a client edit) — same class of silent peer-credential loss, different path (
client_inbound_apply.go, per-inbound peer fields), not a shared root cause.Evidence:
internal/amneziawg/instance.go:39,50-52;internal/web/service/client_wireguard.go:136-140(empty in → empty out,nilerror);internal/web/service/inbound_amneziawg.go:62-65,152-160,163-164,196-200,264-268;internal/web/job/amneziawg_job.go:32-35;internal/web/service/inbound.go:1332-1342,1476,1493,1886-1901;internal/web/service/client_amneziawg.go:38-39,63-69,70-87;internal/web/service/client_inbound_apply.go:409;internal/amneziawg/params.go:281-288;frontend/src/pages/clients/amneziawgConfig.ts:104;frontend/src/pages/api-docs/endpoints.ts:63,296,1031-1036;internal/web/translation/en-US.json:874. No test pins either behaviour:internal/web/service/inbound_amneziawg_test.gocoversallowedIPscanonicalization (TestNormalizeAmneziaWGSettings_CanonicalizesClientAllowedIPs) and newline injection (..._RejectsInjectedClientAllowedIPs), but nothing for an empty list, andTestNormalizeAmneziaWGSettings_GeneratesFull31Setonly asserts the empty-settings/first-save path.Not determined: Nothing material. I could not run the panel here, so the
ss -ulnpandjournalctlobservations are yours, not mine — but they are what the cited code paths predict, so I did not treat them as needing independent confirmation.Suggested fix: In
normalizeAmneziaWGSettings, treat an amneziawg client whoseallowedIPsnormalizes to empty as a validation error naming the client, the same way the injection and collision checks already do, rather than letting a dead peer reachInstanceFromInbound. For the server block, derivepublicKeyfromprivateKeywhen only the private half was sent, and gatefillAmneziaWGServerKeyson "no keys at all" so a half-supplied pair fails loudly instead of producing a blankPublicKey =.@MHSanaei — flagging this one: silent, unlogged loss of an AmneziaWG inbound on one path, and silent rotation/blanking of the server keypair on the other, both reachable from the documented REST API.
This reply was generated automatically; a maintainer may follow up.