[PR #6531] [MERGED] fix(amneziawg): read the outbound pseudo-protocol id like the core #6337

Closed
opened 2026-11-02 04:08:03 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6531
Author: @BlindMaster24
Created: 9/14/2026
Status: ✅ Merged
Merged: 9/15/2026
Merged by: @BlindMaster24

Base: main ← Head: fix/amneziawg-outbound-protocol-id-case


📝 Commits (2)

  • 6e91a54 fix(amneziawg): read the outbound pseudo-protocol id like the core
  • 86236de style(service): trim the amneziawg outbound test comment to two lines

📊 Changes

2 files changed (+47 additions, -1 deletions)

View changed files

📝 internal/amneziawg/outbound.go (+1 -1)
📝 internal/web/service/xray_amneziawg_outbound_test.go (+46 -0)

📄 Description

Summary

amneziawg.IsAmneziaWGOutbound compared the outbound protocol id exactly. It is the last reader of that id that does; the id is now read case-insensitively, like the core and like this repository's own probe lane already read it.

Why

An outbound protocol id is not case-sensitive. The pinned core lowercases it before resolving the handler, and this repository already relies on that everywhere else:

  • internal/web/service/outbound/probe_http.go:399 — the probe lane reads this same id with strings.EqualFold(p, "amneziawg"), and TestBuildBatchTestConfigReadsTheProtocolIDLikeTheCore (merged in #6526) pins that an "AmneziaWG" entry is bridged to socks for the temp probe config.
  • internal/database/db.go reads protocol ids with strings.EqualFold in five migrations (:1634, :1720, :1835, :2153, :2256), including hasNonLowercaseFreedomOutbound (:2330), which exists precisely because non-lowercase protocol ids were found in real stored templates.

IsAmneziaWGOutbound is the exception, and three paths depend on it:

1. Config generation — Xray fails to start. transformAmneziaWGOutbounds (xray_amneziawg_outbound.go:25) skips the entry, so the raw "AmneziaWG" pseudo-protocol is handed to the core. Verified by running the core's own validator:

"AmneziaWG"  -> ValidateOutboundConfig err = infra/conf: failed to load outbound detour config
                for protocol AmneziaWG > infra/conf: unknown config id: amneziawg
"amneziawg"  -> ValidateOutboundConfig err = ... unknown config id: amneziawg

The core does not know amneziawg at all — it is a panel pseudo-protocol that only works because the panel swaps it for a socks bridge before writing the config. Skipping the bridge therefore does not degrade the outbound, it makes the whole config unusable.

2. The amneziawg job — silent no-op. internal/web/job/amneziawg_job.go:82 uses the same predicate, so the reconcile loop never builds an OutboundDesired for the entry: the outbound carries no tunnel and nothing is logged.

3. The save path answered two ways for one spelling. CheckXrayConfig (xray_setting.go:64) branches on the same predicate: the exact match goes to the panel's own validator, the case variant falls through to the core's. Same probe run, before the fix:

"AmneziaWG"  CheckXrayConfig err = xray core rejects outbound "t1": ... unknown config id: amneziawg
"amneziawg"  CheckXrayConfig err = amneziawg outbound "t1": privateKey is required

So an operator writing "AmneziaWG" was told the core has no such protocol, about a protocol the panel implements and whose lowercase spelling it accepts. After the fix both spellings get the panel's own message (amneziawg outbound "t1": privateKey is required), which is the actionable one.

Reachability, stated honestly

The panel's save path rejects the case variant today — that is exactly why the operator sees the confusing message above rather than a stored template. So paths 1 and 2 need a template that did not come through that save: a restored backup, a direct DB edit, a scripted template, or a legacy DB. The UppercaseFreedomFinalRulesFix seeder (and the hasNonLowercaseFreedomOutbound predicate it is built on) is the repository's own evidence that such data exists in the wild, and it repairs it in place rather than rejecting it — the same choice this PR makes for the other pseudo-protocol.

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?

Red-first: TestTransformAmneziaWGOutbounds_ReadsTheProtocolIDLikeTheCore drives the real generation path (transformAmneziaWGOutbounds) for three spellings, and the control case ("amneziawg") passes while the two case variants fail before the fix:

--- FAIL: .../AmneziaWG
    protocol = "AmneziaWG", want "socks": the bridge never ran, so the raw pseudo-protocol reaches the core
    settings = {Address: Port:0 User:}, want the socks bridge for tag "awg-hop" on port 64900
--- FAIL: .../AMNEZIAWG
    (same two assertions)
--- PASS: .../amneziawg

After the change all three are bridged with the tag preserved and the settings rewritten (address 127.0.0.1, port 64900, user awg-hop). Revert strings.EqualFold back to == and the two failures return.

The save-path claim above is a command result rather than a test: the three lines per spelling come from a throwaway probe that called IsAmneziaWGOutbound, xray.ValidateOutboundConfig and CheckXrayConfig on the same outbound. The probe is not part of this PR.

Local gate. go build ./... clean, gofmt -l clean, go vet clean on internal/amneziawg/, internal/web/service/ and internal/web/job/; go test ./internal/amneziawg/ ok and the TestTransformAmneziaWGOutbounds* group green (4 tests). This machine has no C compiler, so the CGo build and the DB-backed tests in internal/web/service are CI's — the full package cannot run locally (it fails identically on unmodified main), which is environmental and not this change.

Screenshots / recordings

N/A — backend and config generation only, no UI change.

Breaking changes

None. The canonical spelling behaves exactly as before; the change only widens which entries the panel recognizes as its own amneziawg pseudo-protocol, and the control case pins that.

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.

go build ./... passes here; the full go test ./... needs a C compiler for the SQLite driver, which CI has and this machine does not — the same caveat as my previous PRs.


🔄 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/6531 **Author:** [@BlindMaster24](https://github.com/BlindMaster24) **Created:** 9/14/2026 **Status:** ✅ Merged **Merged:** 9/15/2026 **Merged by:** [@BlindMaster24](https://github.com/BlindMaster24) **Base:** `main` ← **Head:** `fix/amneziawg-outbound-protocol-id-case` --- ### 📝 Commits (2) - [`6e91a54`](https://github.com/MHSanaei/3x-ui/commit/6e91a54747eee1355fd48898d0412171edf7c054) fix(amneziawg): read the outbound pseudo-protocol id like the core - [`86236de`](https://github.com/MHSanaei/3x-ui/commit/86236deb8cb92cac10815dc298539ab3a5dac228) style(service): trim the amneziawg outbound test comment to two lines ### 📊 Changes **2 files changed** (+47 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `internal/amneziawg/outbound.go` (+1 -1) 📝 `internal/web/service/xray_amneziawg_outbound_test.go` (+46 -0) </details> ### 📄 Description ## Summary `amneziawg.IsAmneziaWGOutbound` compared the outbound protocol id exactly. It is the last reader of that id that does; the id is now read case-insensitively, like the core and like this repository's own probe lane already read it. ## Why An outbound protocol id is not case-sensitive. The pinned core lowercases it before resolving the handler, and this repository already relies on that everywhere else: - `internal/web/service/outbound/probe_http.go:399` — the probe lane reads this same id with `strings.EqualFold(p, "amneziawg")`, and `TestBuildBatchTestConfigReadsTheProtocolIDLikeTheCore` (merged in #6526) pins that an `"AmneziaWG"` entry is bridged to `socks` for the temp probe config. - `internal/database/db.go` reads protocol ids with `strings.EqualFold` in five migrations (`:1634`, `:1720`, `:1835`, `:2153`, `:2256`), including `hasNonLowercaseFreedomOutbound` (`:2330`), which exists precisely because non-lowercase protocol ids were found in real stored templates. `IsAmneziaWGOutbound` is the exception, and three paths depend on it: **1. Config generation — Xray fails to start.** `transformAmneziaWGOutbounds` (`xray_amneziawg_outbound.go:25`) skips the entry, so the raw `"AmneziaWG"` pseudo-protocol is handed to the core. Verified by running the core's own validator: ``` "AmneziaWG" -> ValidateOutboundConfig err = infra/conf: failed to load outbound detour config for protocol AmneziaWG > infra/conf: unknown config id: amneziawg "amneziawg" -> ValidateOutboundConfig err = ... unknown config id: amneziawg ``` The core does not know `amneziawg` at all — it is a panel pseudo-protocol that only works because the panel swaps it for a socks bridge before writing the config. Skipping the bridge therefore does not degrade the outbound, it makes the whole config unusable. **2. The amneziawg job — silent no-op.** `internal/web/job/amneziawg_job.go:82` uses the same predicate, so the reconcile loop never builds an `OutboundDesired` for the entry: the outbound carries no tunnel and nothing is logged. **3. The save path answered two ways for one spelling.** `CheckXrayConfig` (`xray_setting.go:64`) branches on the same predicate: the exact match goes to the panel's own validator, the case variant falls through to the core's. Same probe run, before the fix: ``` "AmneziaWG" CheckXrayConfig err = xray core rejects outbound "t1": ... unknown config id: amneziawg "amneziawg" CheckXrayConfig err = amneziawg outbound "t1": privateKey is required ``` So an operator writing `"AmneziaWG"` was told the core has no such protocol, about a protocol the panel implements and whose lowercase spelling it accepts. After the fix both spellings get the panel's own message (`amneziawg outbound "t1": privateKey is required`), which is the actionable one. ### Reachability, stated honestly The panel's save path rejects the case variant today — that is exactly why the operator sees the confusing message above rather than a stored template. So paths 1 and 2 need a template that did not come through that save: a restored backup, a direct DB edit, a scripted template, or a legacy DB. The `UppercaseFreedomFinalRulesFix` seeder (and the `hasNonLowercaseFreedomOutbound` predicate it is built on) is the repository's own evidence that such data exists in the wild, and it repairs it in place rather than rejecting it — the same choice this PR makes for the other pseudo-protocol. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [x] 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? Red-first: `TestTransformAmneziaWGOutbounds_ReadsTheProtocolIDLikeTheCore` drives the real generation path (`transformAmneziaWGOutbounds`) for three spellings, and the control case (`"amneziawg"`) passes while the two case variants fail before the fix: ``` --- FAIL: .../AmneziaWG protocol = "AmneziaWG", want "socks": the bridge never ran, so the raw pseudo-protocol reaches the core settings = {Address: Port:0 User:}, want the socks bridge for tag "awg-hop" on port 64900 --- FAIL: .../AMNEZIAWG (same two assertions) --- PASS: .../amneziawg ``` After the change all three are bridged with the tag preserved and the settings rewritten (`address 127.0.0.1`, `port 64900`, `user awg-hop`). Revert `strings.EqualFold` back to `==` and the two failures return. The save-path claim above is a command result rather than a test: the three lines per spelling come from a throwaway probe that called `IsAmneziaWGOutbound`, `xray.ValidateOutboundConfig` and `CheckXrayConfig` on the same outbound. The probe is not part of this PR. **Local gate.** `go build ./...` clean, `gofmt -l` clean, `go vet` clean on `internal/amneziawg/`, `internal/web/service/` and `internal/web/job/`; `go test ./internal/amneziawg/` ok and the `TestTransformAmneziaWGOutbounds*` group green (4 tests). This machine has no C compiler, so the CGo build and the DB-backed tests in `internal/web/service` are CI's — the full package cannot run locally (it fails identically on unmodified `main`), which is environmental and not this change. ## Screenshots / recordings N/A — backend and config generation only, no UI change. ## Breaking changes None. The canonical spelling behaves exactly as before; the change only widens which entries the panel recognizes as its own amneziawg pseudo-protocol, and the control case pins that. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] 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. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. `go build ./...` passes here; the full `go test ./...` needs a C compiler for the SQLite driver, which CI has and this machine does not — the same caveat as my previous PRs. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:03 +07:00
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#6337
No description provided.