[PR #6515] [MERGED] fix(xray): place the freedom domain strategy where the core reads it #6321

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

📋 Pull Request Information

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

Base: main ← Head: fix/freedom-domain-strategy-placement


📝 Commits (3)

  • 5e2dc65 fix(xray): place the freedom domain strategy where the core reads it
  • a2e19d9 test(database): seed the template row the seeder test needs
  • 63eee52 fix(xray): keep one strategy control per outbound, seed the row in tests

📊 Changes

14 files changed (+897 additions, -61 deletions)

View changed files

📝 frontend/src/lib/xray/outbound-form-adapter.ts (+50 -10)
📝 frontend/src/pages/xray/basics/BasicsTab.tsx (+3 -24)
📝 frontend/src/pages/xray/basics/constants.ts (+3 -1)
📝 frontend/src/pages/xray/basics/helpers.ts (+42 -0)
📝 frontend/src/pages/xray/outbounds/OutboundFormModal.tsx (+15 -8)
📝 frontend/src/pages/xray/outbounds/transport/sockopt.tsx (+24 -12)
➕ frontend/src/test/basics-freedom-strategy.test.ts (+98 -0)
➕ frontend/src/test/freedom-strategy-placement.test.ts (+154 -0)
📝 frontend/src/test/outbound-form-adapter.test.ts (+8 -4)
📝 frontend/src/test/outbound-form-modal.test.tsx (+48 -0)
📝 internal/database/db.go (+120 -1)
➕ internal/database/freedom_domain_strategy_migration_test.go (+295 -0)
📝 internal/web/service/config.json (+0 -1)
➕ internal/web/service/default_template_freedom_test.go (+37 -0)

📄 Description

Summary

Freedom's domain strategy is now written where xray-core actually reads it —
streamSettings.sockopt.domainStrategy — instead of the two legacy keys the
panel used (settings.domainStrategy and the outbound-root targetStrategy),
and a one-shot seeder moves the keys for configs already stored in the database.

Why

Refs #6482. The pinned core migrates both legacy placements and warns on every
config load (infra/conf/xray.go:345-368):

if strategy = senderSettings.TargetStrategy; strategy != AS_IS {
    LogWarning(`The "outbound.targetStrategy" setting is not supported directly by freedom and has been automatically migrated to "sockopt.domainStrategy" with no behavior change.`)
    senderSettings.TargetStrategy = AS_IS
} else if strategy = fc.DomainStrategy; strategy != AS_IS {
    LogWarning(`The "freedom.domainStrategy" setting is deprecated and will be removed. For compatibility, its value has been automatically migrated to "sockopt.domainStrategy". Please update your config before removal.`)
}

and proxy/freedom/freedom.go:54-58 is what consumes it at runtime
(h.resolveStrategy = streamSettings.SocketSettings.DomainStrategy) — the
legacy keys only ever feed that migration, they never resolve anything
themselves.

The panel emitted both of them, in four places:

  • Xray Settings → Basics → "Freedom Protocol Strategy" wrote
    settings.domainStrategy on the direct outbound.
  • The outbound form: the freedom card's Strategy field wrote the same key
    (through freedomToWire), and the shared Target Strategy field above it
    wrote the outbound-root one — two knobs the core folds into a single value,
    with the root key silently winning.
  • The routing helper injected settings.domainStrategy: "UseIPv4" on the
    IPv4 outbound that service/domain rules bind to (ipv4Settings).
  • The shipped default template (internal/web/service/config.json) carried
    settings.domainStrategy: "AsIs".

User story: on a fresh install I pick UseIPv4 in the Freedom Protocol Strategy
select — or I just tick a service rule, which creates the IPv4 outbound for me.
From then on, every xray start writes the deprecation warning into the panel log
and keeps writing it after every upgrade, with nothing in the UI explaining why
and no way to silence it short of hand-editing the config JSON.

What changed

  • freedomDomainStrategyFromWire reads the strategy in the loader's own
    precedence (root targetStrategy → settings.targetStrategy →
    settings.domainStrategy → existing sockopt), so the card keeps showing the
    value the core would run with rather than one it is about to discard.
  • formValuesToWirePayload hoists the chosen strategy into
    streamSettings.sockopt.domainStrategy and deletes both legacy keys, so a
    single save cleans up a config that older panels wrote. AsIs (and an empty
    field) removes the key instead of emitting an inert value.
  • The shared outbound-root Target Strategy field is hidden for freedom: the
    core migrates that key into the very same sockopt value the card writes, so
    offering both would be two controls for one setting.
  • The Basics select writes sockopt and drops the legacy keys; ipv4Settings and
    the shipped default template no longer carry them.
  • FreedomDomainStrategyFix (a seeder in the OutboundRemovedKeysFix family)
    rewrites an existing xrayTemplateConfig once on upgrade: it moves the value
    to sockopt using the same precedence the loader uses, and drops the legacy
    keys. A value the core refuses to load is dropped rather than migrated, since
    sockopt.domainStrategy rejects it too.

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?

Frontend, npx vitest run on the four touched files (55 tests, all passing):

  • freedom-strategy-placement.test.ts (new, 11): the round trip that matters —
    the card's strategy lands in sockopt, neither legacy key survives, a legacy
    root key is migrated, a legacy AsIs alias does not mask a real sockopt value,
    a cleared field drops the key, an existing sockopt spelling is normalized, and
    the root targetStrategy still rides at the root for non-freedom protocols.
  • basics-freedom-strategy.test.ts (new, 6): the Basics select writes sockopt,
    clears both legacy keys, keeps sibling sockopt keys, and reads back the value
    the core would resolve.
  • outbound-form-adapter.test.ts + outbound-form-modal.test.tsx (updated): the
    existing targetStrategy pins now expect the sockopt placement, and the modal
    test switches protocol to freedom and asserts the root field is gone.

Red before green: reverting the hoist in formValuesToWirePayload makes 6 of
the 11 placement tests fail with the pre-fix payload
(settings.domainStrategy), and re-adding settings.domainStrategy to the
shipped template fails the new Go template test with freedom outbound direct carries the deprecated settings.domainStrategy.

Backend: internal/database/freedom_domain_strategy_migration_test.go has a
table over the rewrite (root key wins over the settings key, settings
targetStrategy wins over domainStrategy, AsIs leaves an existing sockopt
value alone, unknown spellings are dropped, other protocols untouched), plus
TestRewriteFreedomDomainStrategySatisfiesCore, which drives the real vendored
core
: it validates the legacy outbound, asserts the core's own warning was
emitted (captured through log.RegisterHandler), rewrites, and asserts the
rewritten outbound is accepted and no longer warns. That test is red without
the rewrite.

Local caveat worth stating: this machine has no C compiler, so I verified with
CGO_ENABLED=0 go vet ./... plus a local -overlay build that stubs the one
cgo-only call in db.go (sqlite3.SQLiteConn.Backup); no PR file is
substituted. Under that build go test ./internal/database/ -run FreedomDomainStrategy is green and the seeder test skips itself explicitly
(sqlite needs cgo), so the DB-backed path — the seeder runs against a
throwaway database and asserts the stored template changed, then re-seeds a
legacy template and runs the real seeder list to prove the recorded seeder does
not rewrite it again — is exercised by CI, where gcc is present. npm run typecheck,
npm run lint, npm run format:check and npx vite build are clean.

(The two unrelated failures I see locally are environment-only: the
input-number-guard test execFileSyncs ./node_modules/.bin/oxlint, which is
not directly executable on Windows, and language-scope trips the 5s timeout.)

Screenshots / recordings

N/A — no new UI, one field is hidden for a single protocol; the modal test
covers it.

Breaking changes

None for users. Existing xrayTemplateConfig values are migrated once on
upgrade by the seeder, and the strategy keeps its value — it only moves to the
placement the core itself migrates it to, so behavior is unchanged on every core
that emits the warning in the first place.

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. (See the cgo caveat above: verified cgo-free with an overlay that only stubs the cgo-only driver call; CI runs the full build and the DB-backed test.)
  • 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/6515 **Author:** [@BlindMaster24](https://github.com/BlindMaster24) **Created:** 9/14/2026 **Status:** ✅ Merged **Merged:** 9/14/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/freedom-domain-strategy-placement` --- ### 📝 Commits (3) - [`5e2dc65`](https://github.com/MHSanaei/3x-ui/commit/5e2dc6565272b7f8c7dd8dc509d8deed5c409387) fix(xray): place the freedom domain strategy where the core reads it - [`a2e19d9`](https://github.com/MHSanaei/3x-ui/commit/a2e19d93325c7980d7785703a7601ccb6c03613c) test(database): seed the template row the seeder test needs - [`63eee52`](https://github.com/MHSanaei/3x-ui/commit/63eee5258811c8551f45bdda0dfb19b5920083a2) fix(xray): keep one strategy control per outbound, seed the row in tests ### 📊 Changes **14 files changed** (+897 additions, -61 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/lib/xray/outbound-form-adapter.ts` (+50 -10) 📝 `frontend/src/pages/xray/basics/BasicsTab.tsx` (+3 -24) 📝 `frontend/src/pages/xray/basics/constants.ts` (+3 -1) 📝 `frontend/src/pages/xray/basics/helpers.ts` (+42 -0) 📝 `frontend/src/pages/xray/outbounds/OutboundFormModal.tsx` (+15 -8) 📝 `frontend/src/pages/xray/outbounds/transport/sockopt.tsx` (+24 -12) ➕ `frontend/src/test/basics-freedom-strategy.test.ts` (+98 -0) ➕ `frontend/src/test/freedom-strategy-placement.test.ts` (+154 -0) 📝 `frontend/src/test/outbound-form-adapter.test.ts` (+8 -4) 📝 `frontend/src/test/outbound-form-modal.test.tsx` (+48 -0) 📝 `internal/database/db.go` (+120 -1) ➕ `internal/database/freedom_domain_strategy_migration_test.go` (+295 -0) 📝 `internal/web/service/config.json` (+0 -1) ➕ `internal/web/service/default_template_freedom_test.go` (+37 -0) </details> ### 📄 Description ## Summary Freedom's domain strategy is now written where xray-core actually reads it — `streamSettings.sockopt.domainStrategy` — instead of the two legacy keys the panel used (`settings.domainStrategy` and the outbound-root `targetStrategy`), and a one-shot seeder moves the keys for configs already stored in the database. ## Why Refs #6482. The pinned core migrates both legacy placements and warns on every config load (`infra/conf/xray.go:345-368`): ```go if strategy = senderSettings.TargetStrategy; strategy != AS_IS { LogWarning(`The "outbound.targetStrategy" setting is not supported directly by freedom and has been automatically migrated to "sockopt.domainStrategy" with no behavior change.`) senderSettings.TargetStrategy = AS_IS } else if strategy = fc.DomainStrategy; strategy != AS_IS { LogWarning(`The "freedom.domainStrategy" setting is deprecated and will be removed. For compatibility, its value has been automatically migrated to "sockopt.domainStrategy". Please update your config before removal.`) } ``` and `proxy/freedom/freedom.go:54-58` is what consumes it at runtime (`h.resolveStrategy = streamSettings.SocketSettings.DomainStrategy`) — the legacy keys only ever feed that migration, they never resolve anything themselves. The panel emitted both of them, in four places: - **Xray Settings → Basics → "Freedom Protocol Strategy"** wrote `settings.domainStrategy` on the `direct` outbound. - The **outbound form**: the freedom card's Strategy field wrote the same key (through `freedomToWire`), and the shared **Target Strategy** field above it wrote the outbound-root one — two knobs the core folds into a single value, with the root key silently winning. - The **routing helper** injected `settings.domainStrategy: "UseIPv4"` on the `IPv4` outbound that service/domain rules bind to (`ipv4Settings`). - The shipped **default template** (`internal/web/service/config.json`) carried `settings.domainStrategy: "AsIs"`. User story: on a fresh install I pick `UseIPv4` in the Freedom Protocol Strategy select — or I just tick a service rule, which creates the `IPv4` outbound for me. From then on, every xray start writes the deprecation warning into the panel log and keeps writing it after every upgrade, with nothing in the UI explaining why and no way to silence it short of hand-editing the config JSON. ## What changed - `freedomDomainStrategyFromWire` reads the strategy in the loader's own precedence (root `targetStrategy` → `settings.targetStrategy` → `settings.domainStrategy` → existing sockopt), so the card keeps showing the value the core would run with rather than one it is about to discard. - `formValuesToWirePayload` hoists the chosen strategy into `streamSettings.sockopt.domainStrategy` and deletes both legacy keys, so a single save cleans up a config that older panels wrote. `AsIs` (and an empty field) removes the key instead of emitting an inert value. - The shared outbound-root **Target Strategy** field is hidden for freedom: the core migrates that key into the very same sockopt value the card writes, so offering both would be two controls for one setting. - The Basics select writes sockopt and drops the legacy keys; `ipv4Settings` and the shipped default template no longer carry them. - `FreedomDomainStrategyFix` (a seeder in the `OutboundRemovedKeysFix` family) rewrites an existing `xrayTemplateConfig` once on upgrade: it moves the value to sockopt using the same precedence the loader uses, and drops the legacy keys. A value the core refuses to load is dropped rather than migrated, since `sockopt.domainStrategy` rejects it too. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [x] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [x] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? Frontend, `npx vitest run` on the four touched files (55 tests, all passing): - `freedom-strategy-placement.test.ts` (new, 11): the round trip that matters — the card's strategy lands in sockopt, neither legacy key survives, a legacy root key is migrated, a legacy `AsIs` alias does not mask a real sockopt value, a cleared field drops the key, an existing sockopt spelling is normalized, and the root `targetStrategy` still rides at the root for non-freedom protocols. - `basics-freedom-strategy.test.ts` (new, 6): the Basics select writes sockopt, clears both legacy keys, keeps sibling sockopt keys, and reads back the value the core would resolve. - `outbound-form-adapter.test.ts` + `outbound-form-modal.test.tsx` (updated): the existing targetStrategy pins now expect the sockopt placement, and the modal test switches protocol to freedom and asserts the root field is gone. Red before green: reverting the hoist in `formValuesToWirePayload` makes 6 of the 11 placement tests fail with the pre-fix payload (`settings.domainStrategy`), and re-adding `settings.domainStrategy` to the shipped template fails the new Go template test with `freedom outbound direct carries the deprecated settings.domainStrategy`. Backend: `internal/database/freedom_domain_strategy_migration_test.go` has a table over the rewrite (root key wins over the settings key, settings `targetStrategy` wins over `domainStrategy`, `AsIs` leaves an existing sockopt value alone, unknown spellings are dropped, other protocols untouched), plus `TestRewriteFreedomDomainStrategySatisfiesCore`, which drives the *real vendored core*: it validates the legacy outbound, asserts the core's own warning was emitted (captured through `log.RegisterHandler`), rewrites, and asserts the rewritten outbound is accepted **and** no longer warns. That test is red without the rewrite. Local caveat worth stating: this machine has no C compiler, so I verified with `CGO_ENABLED=0 go vet ./...` plus a local `-overlay` build that stubs the one cgo-only call in `db.go` (`sqlite3.SQLiteConn.Backup`); no PR file is substituted. Under that build `go test ./internal/database/ -run FreedomDomainStrategy` is green and the seeder test skips itself explicitly (`sqlite needs cgo`), so the DB-backed path — the seeder runs against a throwaway database and asserts the stored template changed, then re-seeds a legacy template and runs the real seeder list to prove the recorded seeder does not rewrite it again — is exercised by CI, where gcc is present. `npm run typecheck`, `npm run lint`, `npm run format:check` and `npx vite build` are clean. (The two unrelated failures I see locally are environment-only: the `input-number-guard` test `execFileSync`s `./node_modules/.bin/oxlint`, which is not directly executable on Windows, and `language-scope` trips the 5s timeout.) ## Screenshots / recordings N/A — no new UI, one field is hidden for a single protocol; the modal test covers it. ## Breaking changes None for users. Existing `xrayTemplateConfig` values are migrated once on upgrade by the seeder, and the strategy keeps its value — it only moves to the placement the core itself migrates it to, so behavior is unchanged on every core that emits the warning in the first place. ## 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. (See the cgo caveat above: verified cgo-free with an overlay that only stubs the cgo-only driver call; CI runs the full build and the DB-backed test.) - [x] 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:56 +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#6321
No description provided.