[GH-ISSUE #6410] [Bug]: AmneziaWG is not handled correctly in JSON subscription #4341

Closed
opened 2026-10-31 20:38:57 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @barbod1123-bit on GitHub (Sep 4, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6410

Describe the bug

After AmneziaWG support was added in 3X-UI 3.7.0, AmneziaWG nodes are included in the subscription when using the JSON format.

How to reproduce the problem

However, AmneziaWG does not support the JSON subscription format currently generated by 3X-UI. As a result, the generated JSON subscription is not compatible with AmneziaWG clients.

Expected behavior

The subscription system should properly handle AmneziaWG configurations, or exclude AmneziaWG nodes when the selected subscription format is incompatible with this protocol.

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.7.0

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 22

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @barbod1123-bit on GitHub (Sep 4, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6410 ### Describe the bug After AmneziaWG support was added in 3X-UI 3.7.0, AmneziaWG nodes are included in the subscription when using the JSON format. ### How to reproduce the problem However, AmneziaWG does not support the JSON subscription format currently generated by 3X-UI. As a result, the generated JSON subscription is not compatible with AmneziaWG clients. ### Expected behavior The subscription system should properly handle AmneziaWG configurations, or exclude AmneziaWG nodes when the selected subscription format is incompatible with this protocol. ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.7.0 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 22 ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:38:57 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Sep 4, 2026):

Confirmed — this is a real bug, and it is still present on the default branch. An AmneziaWG inbound is selected for a JSON subscription, but SubJsonService.getConfig has no branch for it, so the entry it emits contains no proxy outbound at all.

Where it goes wrong

The inbound is deliberately included in the subscription query — the protocol is in the allowlist:

// internal/sub/service.go:494
inbounds.protocol in ('vmess','vless','trojan','shadowsocks','hysteria','wireguard','amneziawg','mtproto')

The raw /sub/ body then builds a correct link for it (internal/sub/service.go:645-646 → genAmneziaWGLink, which returns "vpn://" + base64.RawURLEncoding.EncodeToString([]byte(text)), internal/sub/service.go:820).

The JSON generator does not. Its protocol switch stops at wireguard:

// internal/sub/json_service.go:568-592
switch inbound.Protocol {
case "vmess":  ...
case "vless":  ...
case "trojan", "shadowsocks": ...
case "hysteria": ...
case "wireguard":
	wgOutbound := s.genWireguard(inbound, client)
	if wgOutbound == nil {
		continue
	}
	newOutbounds = append(newOutbounds, wgOutbound)
}

amneziawg matches no case. Unlike the wireguard case there is no continue, so execution falls straight through to

// internal/sub/json_service.go:594
newOutbounds = append(newOutbounds, s.defaultOutbounds...)

and the entry is appended to the array at internal/sub/json_service.go:603. The default outbounds are only direct (freedom) and block (blackhole) (internal/sub/default.json:45-63), while the routing rule copied into every entry sends all traffic to a tag that is now absent:

// internal/sub/default.json:85
{ "type": "field", "network": "tcp,udp", "outboundTag": "proxy" }

So each AmneziaWG client gets a named, non-functional entry in /json/. For comparison, the Clash generator handles the same gap by dropping the proxy instead of emitting a broken one (default: return nil, internal/sub/clash_service.go:294-295) — that omission is tracked separately as #6310.

Your second suggestion is the realistic one: AmneziaWG is not an Xray outbound protocol in this panel at all — it runs in-process over a userspace netstack (internal/amneziawgnet/, see internal/xray/hot_diff.go:302-303), so an Xray JSON config has no field that can carry the tunnel or its obfuscation parameters.

Workaround

Use the raw subscription (/sub/…) rather than the JSON one for AmneziaWG clients, or export the client from the panel directly — both already produce a valid payload (a vpn://… link or the .conf text) that the AmneziaVPN/AmneziaWG app imports. See Configuration → AmneziaWG.

Verdict: Confirmed bug
Severity: Medium
Confidence: High
Root cause: SubJsonService.getConfig, internal/sub/json_service.go:568-592 — the switch inbound.Protocol has no amneziawg case (nor mtproto), and, unlike the wireguard case at :586-591, nothing skips the entry, so control reaches newOutbounds = append(newOutbounds, s.defaultOutbounds...) at :594 and a config whose only outbounds are direct and block is appended at :603. Triggering condition: any enabled amneziawg inbound with a client carrying the requested subId, fetched through the JSON subscription format. Introduced by effcccce "feat(amneziawg): add native AmneziaWG protocol support (#6105)", which added 'amneziawg' to the getInboundsBySubId allowlist (internal/sub/service.go:494) and to GetLink (internal/sub/service.go:645) but not to the JSON or Clash generators.
Already fixed: Still present on the default branch (3ef06b70, after v3.7.0). The equivalent defect for native WireGuard was fixed in d2efe9b0 "fix(sub): include native WireGuard clients in Clash and JSON subscriptions (#5676)" — that commit added exactly the branch AmneziaWG is still missing.
Duplicate of: None. Related: #6310 covers the same feature gap in the Clash generator; the open PR for it, #6326, changes only internal/sub/clash_service.go and internal/sub/clash_service_test.go, so it does not touch this path. mtproto hits the identical fall-through in the same switch.
Evidence: internal/sub/service.go:494 (allowlist includes 'amneziawg'); internal/sub/service.go:645-646 and :820 (raw link works, vpn:// + base64url); internal/sub/json_service.go:568-592 (switch with no amneziawg case), :586-591 (the continue the WireGuard case has), :594 (s.defaultOutbounds...), :603 (entry appended); internal/sub/default.json:45-63 (direct/block only) and :85 ("outboundTag": "proxy"); internal/sub/clash_service.go:294-295 (default: return nil — the other generator skips instead); TestGetInboundsBySubIdIncludesAmneziaWG (internal/sub/service_amneziawg_test.go:165-189) pins only the DB selection, and internal/sub/json_service_test.go contains no AmneziaWG case — nothing asserts the current output as intended.
Not determined: Whether a client fed this entry errors out or silently routes the traffic direct through the direct freedom outbound (the routing rule targets a tag that does not exist in the config). I cannot run Xray here; reading xray-core's router fallback for an unresolvable outboundTag settles it, and it decides whether this is a dead entry or a leak.

Suggested fix: In getConfig, give amneziawg (and mtproto) an explicit continue alongside the wireguard case, so the JSON format skips a protocol it cannot express instead of emitting a proxy-less config — matching what internal/sub/clash_service.go:294-295 already does. A test in internal/sub/json_service_test.go asserting that an AmneziaWG-only subId yields an empty JSON array would pin it.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:5540594451 --> @github-actions[bot] commented on GitHub (Sep 4, 2026): Confirmed — this is a real bug, and it is still present on the default branch. An AmneziaWG inbound *is* selected for a JSON subscription, but `SubJsonService.getConfig` has no branch for it, so the entry it emits contains no proxy outbound at all. ### Where it goes wrong The inbound is deliberately included in the subscription query — the protocol is in the allowlist: ```go // internal/sub/service.go:494 inbounds.protocol in ('vmess','vless','trojan','shadowsocks','hysteria','wireguard','amneziawg','mtproto') ``` The raw `/sub/` body then builds a correct link for it (`internal/sub/service.go:645-646` → `genAmneziaWGLink`, which returns `"vpn://" + base64.RawURLEncoding.EncodeToString([]byte(text))`, `internal/sub/service.go:820`). The JSON generator does not. Its protocol switch stops at `wireguard`: ```go // internal/sub/json_service.go:568-592 switch inbound.Protocol { case "vmess": ... case "vless": ... case "trojan", "shadowsocks": ... case "hysteria": ... case "wireguard": wgOutbound := s.genWireguard(inbound, client) if wgOutbound == nil { continue } newOutbounds = append(newOutbounds, wgOutbound) } ``` `amneziawg` matches no case. Unlike the `wireguard` case there is no `continue`, so execution falls straight through to ```go // internal/sub/json_service.go:594 newOutbounds = append(newOutbounds, s.defaultOutbounds...) ``` and the entry is appended to the array at `internal/sub/json_service.go:603`. The default outbounds are only `direct` (freedom) and `block` (blackhole) (`internal/sub/default.json:45-63`), while the routing rule copied into every entry sends all traffic to a tag that is now absent: ```json // internal/sub/default.json:85 { "type": "field", "network": "tcp,udp", "outboundTag": "proxy" } ``` So each AmneziaWG client gets a named, non-functional entry in `/json/`. For comparison, the Clash generator handles the same gap by dropping the proxy instead of emitting a broken one (`default: return nil`, `internal/sub/clash_service.go:294-295`) — that omission is tracked separately as #6310. Your second suggestion is the realistic one: AmneziaWG is not an Xray outbound protocol in this panel at all — it runs in-process over a userspace netstack (`internal/amneziawgnet/`, see `internal/xray/hot_diff.go:302-303`), so an Xray JSON config has no field that can carry the tunnel or its obfuscation parameters. ### Workaround Use the raw subscription (`/sub/…`) rather than the JSON one for AmneziaWG clients, or export the client from the panel directly — both already produce a valid payload (a `vpn://…` link or the `.conf` text) that the AmneziaVPN/AmneziaWG app imports. See [Configuration → AmneziaWG](https://docs.sanaei.dev/en/docs/config/amneziawg). Verdict: Confirmed bug Severity: Medium Confidence: High Root cause: `SubJsonService.getConfig`, `internal/sub/json_service.go:568-592` — the `switch inbound.Protocol` has no `amneziawg` case (nor `mtproto`), and, unlike the `wireguard` case at `:586-591`, nothing skips the entry, so control reaches `newOutbounds = append(newOutbounds, s.defaultOutbounds...)` at `:594` and a config whose only outbounds are `direct` and `block` is appended at `:603`. Triggering condition: any enabled `amneziawg` inbound with a client carrying the requested `subId`, fetched through the JSON subscription format. Introduced by `effcccce` "feat(amneziawg): add native AmneziaWG protocol support (#6105)", which added `'amneziawg'` to the `getInboundsBySubId` allowlist (`internal/sub/service.go:494`) and to `GetLink` (`internal/sub/service.go:645`) but not to the JSON or Clash generators. Already fixed: Still present on the default branch (`3ef06b70`, after v3.7.0). The equivalent defect for native WireGuard was fixed in `d2efe9b0` "fix(sub): include native WireGuard clients in Clash and JSON subscriptions (#5676)" — that commit added exactly the branch AmneziaWG is still missing. Duplicate of: None. Related: #6310 covers the same feature gap in the Clash generator; the open PR for it, #6326, changes only `internal/sub/clash_service.go` and `internal/sub/clash_service_test.go`, so it does not touch this path. `mtproto` hits the identical fall-through in the same `switch`. Evidence: `internal/sub/service.go:494` (allowlist includes `'amneziawg'`); `internal/sub/service.go:645-646` and `:820` (raw link works, `vpn://` + base64url); `internal/sub/json_service.go:568-592` (switch with no `amneziawg` case), `:586-591` (the `continue` the WireGuard case has), `:594` (`s.defaultOutbounds...`), `:603` (entry appended); `internal/sub/default.json:45-63` (`direct`/`block` only) and `:85` (`"outboundTag": "proxy"`); `internal/sub/clash_service.go:294-295` (`default: return nil` — the other generator skips instead); `TestGetInboundsBySubIdIncludesAmneziaWG` (`internal/sub/service_amneziawg_test.go:165-189`) pins only the DB selection, and `internal/sub/json_service_test.go` contains no AmneziaWG case — nothing asserts the current output as intended. Not determined: Whether a client fed this entry errors out or silently routes the traffic direct through the `direct` freedom outbound (the routing rule targets a tag that does not exist in the config). I cannot run Xray here; reading xray-core's router fallback for an unresolvable `outboundTag` settles it, and it decides whether this is a dead entry or a leak. Suggested fix: In `getConfig`, give `amneziawg` (and `mtproto`) an explicit `continue` alongside the `wireguard` case, so the JSON format skips a protocol it cannot express instead of emitting a proxy-less config — matching what `internal/sub/clash_service.go:294-295` already does. A test in `internal/sub/json_service_test.go` asserting that an AmneziaWG-only `subId` yields an empty JSON array would pin it. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@barbod1123-bit commented on GitHub (Sep 4, 2026):

To clarify my suggestion: I don't mean adding AmneziaWG as an Xray outbound.

I mean having one JSON subscription URL containing all protocols, while each protocol uses its own configuration format inside the JSON.

For example, Xray protocols (VLESS, VMess, Trojan, etc.) would use their normal Xray configuration structure, while AmneziaWG would have a separate/custom structure containing its own parameters.

This would allow a compatible client to parse each entry based on its "type" and handle AmneziaWG independently from Xray.

So the goal is a unified JSON subscription, not forcing AmneziaWG into the Xray outbound format.

<!-- gh-comment-id:5540656588 --> @barbod1123-bit commented on GitHub (Sep 4, 2026): To clarify my suggestion: I don't mean adding AmneziaWG as an Xray outbound. I mean having one JSON subscription URL containing all protocols, while each protocol uses its own configuration format inside the JSON. For example, Xray protocols (VLESS, VMess, Trojan, etc.) would use their normal Xray configuration structure, while AmneziaWG would have a separate/custom structure containing its own parameters. This would allow a compatible client to parse each entry based on its "type" and handle AmneziaWG independently from Xray. So the goal is a unified JSON subscription, not forcing AmneziaWG into the Xray outbound format.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4341
No description provided.