[PR #7097] feat: import AmneziaWG vpn:// links and subscriptions as outbounds #6649

Open
opened 2026-11-07 21:42:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/7097
Author: @NikanZeyaei
Created: 11/7/2026
Status: 🔄 Open

Base: main ← Head: feat/amneziawg-link-import


📝 Commits (8)

  • fd4974d feat(link): parse AmneziaWG vpn:// links into amneziawg outbounds
  • 736b64b feat(outbound-sub): run AmneziaWG outbounds from subscriptions
  • c7f57f0 feat(frontend): import AmneziaWG vpn:// links in the outbound form
  • 2b0a866 docs(outbounds): list vpn:// among importable link schemes
  • 0254ea7 fix(frontend): keep absent S3/S4 at 0 when importing a vpn:// link
  • 9695b3f perf(outbound-sub): read subscribed AmneziaWG outbounds quietly per job tick
  • fa73ca8 fix(link): bound vpn:// inflation per subscription and keep client identity
  • 7f07e3a fix(frontend): cap inflated AmneziaVPN keys and keep ranged keepalive

📊 Changes

14 files changed (+782 additions, -43 deletions)

View changed files

📝 docs/content/docs/en/operations/outbounds-routing.mdx (+2 -1)
📝 docs/content/docs/fa/operations/outbounds-routing.mdx (+1 -1)
📝 docs/content/docs/ru/operations/outbounds-routing.mdx (+1 -1)
📝 docs/content/docs/zh/operations/outbounds-routing.mdx (+1 -1)
📝 frontend/src/lib/xray/outbound-link-parser.ts (+143 -3)
📝 frontend/src/pages/xray/outbounds/OutboundFormModal.tsx (+3 -3)
📝 frontend/src/test/outbound-link-parser.test.ts (+150 -15)
➕ internal/util/link/amneziawg_test.go (+153 -0)
📝 internal/util/link/outbound.go (+173 -3)
📝 internal/web/job/amneziawg_job.go (+16 -13)
➕ internal/web/job/amneziawg_job_test.go (+56 -0)
📝 internal/web/service/outbound_subscription.go (+37 -2)
📝 internal/web/service/outbound_subscription_test.go (+43 -0)
📝 internal/web/service/xray.go (+3 -0)

📄 Description

Summary

Import AmneziaWG vpn:// links as amneziawg outbounds, both pasted into the outbound form and pulled from outbound subscriptions. Both payload formats are accepted: 3x-ui's base64url .conf text and the AmneziaVPN app's compressed JSON key.

Why

Closes #7056

The panel serves AmneziaWG as vpn:// links and has an amneziawg outbound, but could not import those links. Parsing alone was not enough for subscriptions, because three things dropped or broke a subscribed AmneziaWG outbound:

  • refresh validated it with xray-core, which has no amneziawg protocol, so it was always dropped;
  • GetXrayConfig bridged amneziawg outbounds to socks before the subscription merge, so a subscribed one would have reached the core raw;
  • AmneziaWGJob only started tunnel devices for template outbounds.

Commits:

  1. feat(link): Go vpn:// parser in internal/util/link. Only known .conf keys are copied, so PostUp and other wg-quick hooks never get through. Inflated keys are capped at 1 MiB.
  2. feat(outbound-sub): subscription outbounds are validated with ValidateAmneziaWGOutbound, bridged after the merge, and get their tunnel device.
  3. feat(frontend): the same parser in outbound-link-parser.ts. parseOutboundLink is now async because the browser's only built-in zlib inflater (DecompressionStream) is async. This avoids a new dependency. The key's JSON is validated with Zod.
  4. docs(outbounds): list vpn among the importable schemes (en/fa/ru/zh).

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

New tests. Each one fails when its fix is reverted.

  • internal/util/link/amneziawg_test.go: a 3x-ui plain-text link, an AmneziaVPN qCompress key, a key without a remark (the tag comes from description), a PostUp line that must not appear in the output, and rejections for a key with no AmneziaWG container and a config with no endpoint.
  • TestOutboundSubscriptionAmneziaWGLinkReachesConfigAsBridge: an httptest subscription serving a vpn:// line. The outbound survives refresh and is emitted as socks in GetXrayConfig.
  • TestDesiredOutboundInstancesIncludesSubscribedAmneziaWG: a subscribed outbound gets its tunnel instance.
  • outbound-link-parser.test.ts: the same cases on the frontend.

Checks run:

  • make lint, make format-check, make typecheck, make test-fe, make build, make build-storybook, make docs-openapi-check and the Go tests pass. One Storybook iframe timed out once (FormField.stories.tsx) and passed on rerun.
  • FuzzParseLink ran for 20s.

Manual check: built the panel with Xray v26.10.31 and pasted both link formats under Xray Settings → Outbounds → Add outbound → link import. Both filled the amneziawg form (tags test-awg and amnezia-key).

Cross-panel check: created an AmneziaWG inbound with a client on a separate 3x-ui panel, then added that client's subscription URL as an outbound subscription on the local panel built from this branch. The vpn:// link was imported as an amneziawg outbound and emitted as its socks bridge in the generated Xray config.

Not tested: a real key exported by the AmneziaVPN app. The fixture follows the format described in amnezia-client#1407.

Screenshots / recordings

N/A. The existing link-import box and amneziawg form are unchanged; they now accept vpn://.

Breaking changes

None.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/7097 **Author:** [@NikanZeyaei](https://github.com/NikanZeyaei) **Created:** 11/7/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/amneziawg-link-import` --- ### 📝 Commits (8) - [`fd4974d`](https://github.com/MHSanaei/3x-ui/commit/fd4974d95d6e2385a1966c9b77e47441be54938b) feat(link): parse AmneziaWG vpn:// links into amneziawg outbounds - [`736b64b`](https://github.com/MHSanaei/3x-ui/commit/736b64b8e0d79ef99c5ceb3ee34028a2c0928780) feat(outbound-sub): run AmneziaWG outbounds from subscriptions - [`c7f57f0`](https://github.com/MHSanaei/3x-ui/commit/c7f57f0fd6971d60ffd906650133df81623ab165) feat(frontend): import AmneziaWG vpn:// links in the outbound form - [`2b0a866`](https://github.com/MHSanaei/3x-ui/commit/2b0a8666231dd5040674f521a9ec1ec878eff813) docs(outbounds): list vpn:// among importable link schemes - [`0254ea7`](https://github.com/MHSanaei/3x-ui/commit/0254ea7e9871b5a4ce88cc61531556f103772de2) fix(frontend): keep absent S3/S4 at 0 when importing a vpn:// link - [`9695b3f`](https://github.com/MHSanaei/3x-ui/commit/9695b3f175d658b9ef121031ab6341903ca60721) perf(outbound-sub): read subscribed AmneziaWG outbounds quietly per job tick - [`fa73ca8`](https://github.com/MHSanaei/3x-ui/commit/fa73ca8f6dd45e90b8936d87d8009459892fe228) fix(link): bound vpn:// inflation per subscription and keep client identity - [`7f07e3a`](https://github.com/MHSanaei/3x-ui/commit/7f07e3abb135e47eb40db9b672dc957997b8e5f9) fix(frontend): cap inflated AmneziaVPN keys and keep ranged keepalive ### 📊 Changes **14 files changed** (+782 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/en/operations/outbounds-routing.mdx` (+2 -1) 📝 `docs/content/docs/fa/operations/outbounds-routing.mdx` (+1 -1) 📝 `docs/content/docs/ru/operations/outbounds-routing.mdx` (+1 -1) 📝 `docs/content/docs/zh/operations/outbounds-routing.mdx` (+1 -1) 📝 `frontend/src/lib/xray/outbound-link-parser.ts` (+143 -3) 📝 `frontend/src/pages/xray/outbounds/OutboundFormModal.tsx` (+3 -3) 📝 `frontend/src/test/outbound-link-parser.test.ts` (+150 -15) ➕ `internal/util/link/amneziawg_test.go` (+153 -0) 📝 `internal/util/link/outbound.go` (+173 -3) 📝 `internal/web/job/amneziawg_job.go` (+16 -13) ➕ `internal/web/job/amneziawg_job_test.go` (+56 -0) 📝 `internal/web/service/outbound_subscription.go` (+37 -2) 📝 `internal/web/service/outbound_subscription_test.go` (+43 -0) 📝 `internal/web/service/xray.go` (+3 -0) </details> ### 📄 Description ## Summary Import AmneziaWG `vpn://` links as `amneziawg` outbounds, both pasted into the outbound form and pulled from outbound subscriptions. Both payload formats are accepted: 3x-ui's base64url `.conf` text and the AmneziaVPN app's compressed JSON key. ## Why Closes #7056 The panel serves AmneziaWG as `vpn://` links and has an `amneziawg` outbound, but could not import those links. Parsing alone was not enough for subscriptions, because three things dropped or broke a subscribed AmneziaWG outbound: - refresh validated it with xray-core, which has no `amneziawg` protocol, so it was always dropped; - `GetXrayConfig` bridged `amneziawg` outbounds to socks before the subscription merge, so a subscribed one would have reached the core raw; - `AmneziaWGJob` only started tunnel devices for template outbounds. Commits: 1. `feat(link)`: Go `vpn://` parser in `internal/util/link`. Only known `.conf` keys are copied, so `PostUp` and other wg-quick hooks never get through. Inflated keys are capped at 1 MiB. 2. `feat(outbound-sub)`: subscription outbounds are validated with `ValidateAmneziaWGOutbound`, bridged after the merge, and get their tunnel device. 3. `feat(frontend)`: the same parser in `outbound-link-parser.ts`. `parseOutboundLink` is now async because the browser's only built-in zlib inflater (`DecompressionStream`) is async. This avoids a new dependency. The key's JSON is validated with Zod. 4. `docs(outbounds)`: list `vpn` among the importable schemes (en/fa/ru/zh). ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [x] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [x] Xray config generation - [x] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? New tests. Each one fails when its fix is reverted. - `internal/util/link/amneziawg_test.go`: a 3x-ui plain-text link, an AmneziaVPN qCompress key, a key without a remark (the tag comes from `description`), a `PostUp` line that must not appear in the output, and rejections for a key with no AmneziaWG container and a config with no endpoint. - `TestOutboundSubscriptionAmneziaWGLinkReachesConfigAsBridge`: an `httptest` subscription serving a `vpn://` line. The outbound survives refresh and is emitted as `socks` in `GetXrayConfig`. - `TestDesiredOutboundInstancesIncludesSubscribedAmneziaWG`: a subscribed outbound gets its tunnel instance. - `outbound-link-parser.test.ts`: the same cases on the frontend. Checks run: - `make lint`, `make format-check`, `make typecheck`, `make test-fe`, `make build`, `make build-storybook`, `make docs-openapi-check` and the Go tests pass. One Storybook iframe timed out once (`FormField.stories.tsx`) and passed on rerun. - `FuzzParseLink` ran for 20s. Manual check: built the panel with Xray v26.10.31 and pasted both link formats under Xray Settings → Outbounds → Add outbound → link import. Both filled the amneziawg form (tags `test-awg` and `amnezia-key`). Cross-panel check: created an AmneziaWG inbound with a client on a separate 3x-ui panel, then added that client's subscription URL as an outbound subscription on the local panel built from this branch. The `vpn://` link was imported as an `amneziawg` outbound and emitted as its socks bridge in the generated Xray config. Not tested: a real key exported by the AmneziaVPN app. The fixture follows the format described in amnezia-client#1407. ## Screenshots / recordings N/A. The existing link-import box and amneziawg form are unchanged; they now accept `vpn://`. ## Breaking changes None. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#6649
No description provided.