[PR #6519] [MERGED] fix(xray): migrate the dns outbound off its legacy nonIPQuery and blockTypes #6326

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

📋 Pull Request Information

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

Base: main ← Head: fix/dns-outbound-legacy-keys


📝 Commits (2)

  • f99bf6a fix(xray): migrate the dns outbound off its legacy nonIPQuery and blockTypes
  • ad1b899 fix(xray): read a dns outbound's null keys and protocol id like the core

📊 Changes

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

View changed files

📝 internal/database/db.go (+156 -1)
➕ internal/database/dns_outbound_legacy_keys_migration_test.go (+375 -0)

📄 Description

Summary

A one-shot seeder (DNSOutboundLegacyKeysFix) that converts a stored dns outbound's legacy nonIPQuery / blockTypes into the rules the pinned core reads, then drops both keys. The conversion reproduces the core's own legacy builder, in its order: the blocked qTypes, then the hijack for qType 1/28, then the mode's answer for everything else.

Why

xray-core treats these two keys as removed, and last release they are worse than deprecated — they are a start failure when mixed with rules:

infra/conf/dns_proxy.go:96   return nil, errors.New("legacy nonIPQuery and blockTypes cannot be mixed with rules")
infra/conf/dns_proxy.go:99   This feature "nonIPQuery" and "blockTypes" is deprecated, will be removed soon
                             and being migrated to "rules".

The panel is what put them there. The dns outbound card in the Vue panel wrote both keys with defaults on every save — web/assets/js/model/outbound.js just before a62c6376:

Outbound.DNSSettings = class extends CommonClass {
    constructor(network = 'udp', address = '', port = 53, nonIPQuery = 'reject', blockTypes = []) {
        ...
        this.nonIPQuery = nonIPQuery;
        this.blockTypes = blockTypes;

so a panel that ever created a dns outbound carries nonIPQuery whether or not the operator ever touched that field. a62c6376 replaced the card with rules and kept a read-time conversion; the React rewrite (#4599) dropped that conversion, so on today's panel the legacy policy is not shown in the card and is silently deleted the next time that outbound is saved.

Three user-visible shapes of this:

  1. Upgrade. A panel that configured a dns outbound before the card switched to rules logs the deprecation warning on every xray start, forever, with nothing in the UI pointing at the cause.
  2. Silent policy loss. That operator opens the outbound to change the DNS address. The rules table renders empty, because the adapter no longer maps the legacy keys. They save, and the blocking policy they set up is gone without a word. The seeder converts the policy first, in the placement the card shows and edits.
  3. Hand-edited template. A template carrying both the legacy keys and rules never starts the core at all (the error above). The seeder keeps the rules and drops the legacy keys, which is the only combination the core accepts.

Verified against the vendored core without this change (probe swept across all 55 golden fixtures, the default template and each outbound shape):

PROBE outbound/dns-legacy-keys buildErr=false
   PROBE-WARN ... This feature "nonIPQuery" and "blockTypes" is deprecated ...

While auditing the pinned core for a key it warns about or refuses that the panel still writes, this was the last unhandled one: freedom.domainStrategy is fixed separately (#6515), and freedom.ipsBlocked is already handled by the FreedomFinalRulesReverseFix seeder. Everything else the core prints is a feature notice (VMess/Trojan/shadowsocks/WS/gRPC), not a key the panel should stop writing.

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?

go test ./internal/database/ -run 'DNSOutboundLegacyKeys|RewriteDNSOutboundLegacyKeys' -v

  • Exact output table (8 cases): reject/drop/skip, blockTypes as a list, a bare number and a comma-separated string, a missing mode defaulting to reject as the core does, existing rules winning over the legacy pair, a dns outbound already on rules untouched, and a non-dns outbound with the same key names untouched.
  • Against the real vendored core (xray.ValidateOutboundConfig, with common/log captured via RegisterHandler): the legacy outbound loads with the deprecation warning, the mixed one is refused, and after the rewrite both load with no warning and no error — so the fix is measured on the core's own verdict rather than on the panel's JSON.
  • Mutation-checked, since a migration test that passes either way proves nothing: dropping the generated rules (keeping the key deletion) fails 5 of the table cases; leaving the conversion out fails the core test on changed=false.
  • Seeder path over a real DB: seeds a legacy template, clears the history row, runs the seeder, asserts the stored rules and that both keys are gone; then re-seeds a legacy template and runs the full runSeeders(false) list to prove the history gate stops a second rewrite of a hand-edited template.

Local note, same as the rest of this package's DB tests: this checkout has no C compiler, so Go was exercised with CGO_ENABLED=0 plus an -overlay that stubs the one cgo-only call (sqlite3.SQLiteConn.Backup) — no file in this PR is replaced. The DB-path test self-skips in that build (sqlite needs cgo) and is the one that runs on CI.

Screenshots / recordings

N/A — no UI change.

Breaking changes

None. The seeder runs before the config is generated, and the rules it writes express the same policy the core used to derive from the legacy keys, so a converted outbound behaves as it did. Operators who never had a dns outbound are untouched.

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. (no C compiler here — see the note above; CI runs the cgo path)
  • 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/6519 **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/dns-outbound-legacy-keys` --- ### 📝 Commits (2) - [`f99bf6a`](https://github.com/MHSanaei/3x-ui/commit/f99bf6add8b4c5f06da37a77b4d2e86a6b13a2ff) fix(xray): migrate the dns outbound off its legacy nonIPQuery and blockTypes - [`ad1b899`](https://github.com/MHSanaei/3x-ui/commit/ad1b899d47e37060a72f18094879a95e70acaa0a) fix(xray): read a dns outbound's null keys and protocol id like the core ### 📊 Changes **2 files changed** (+531 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `internal/database/db.go` (+156 -1) ➕ `internal/database/dns_outbound_legacy_keys_migration_test.go` (+375 -0) </details> ### 📄 Description ## Summary A one-shot seeder (`DNSOutboundLegacyKeysFix`) that converts a stored `dns` outbound's legacy `nonIPQuery` / `blockTypes` into the `rules` the pinned core reads, then drops both keys. The conversion reproduces the core's own legacy builder, in its order: the blocked qTypes, then the `hijack` for qType 1/28, then the mode's answer for everything else. ## Why `xray-core` treats these two keys as removed, and last release they are worse than deprecated — they are a **start failure** when mixed with rules: ``` infra/conf/dns_proxy.go:96 return nil, errors.New("legacy nonIPQuery and blockTypes cannot be mixed with rules") infra/conf/dns_proxy.go:99 This feature "nonIPQuery" and "blockTypes" is deprecated, will be removed soon and being migrated to "rules". ``` The panel is what put them there. The dns outbound card in the Vue panel wrote both keys **with defaults** on every save — `web/assets/js/model/outbound.js` just before a62c6376: ```js Outbound.DNSSettings = class extends CommonClass { constructor(network = 'udp', address = '', port = 53, nonIPQuery = 'reject', blockTypes = []) { ... this.nonIPQuery = nonIPQuery; this.blockTypes = blockTypes; ``` so a panel that ever created a dns outbound carries `nonIPQuery` whether or not the operator ever touched that field. a62c6376 replaced the card with `rules` and kept a read-time conversion; the React rewrite (#4599) dropped that conversion, so on today's panel the legacy policy is not shown in the card and is silently deleted the next time that outbound is saved. Three user-visible shapes of this: 1. **Upgrade.** A panel that configured a dns outbound before the card switched to rules logs the deprecation warning on every xray start, forever, with nothing in the UI pointing at the cause. 2. **Silent policy loss.** That operator opens the outbound to change the DNS address. The rules table renders empty, because the adapter no longer maps the legacy keys. They save, and the blocking policy they set up is gone without a word. The seeder converts the policy first, in the placement the card shows and edits. 3. **Hand-edited template.** A template carrying both the legacy keys and `rules` never starts the core at all (the error above). The seeder keeps the rules and drops the legacy keys, which is the only combination the core accepts. Verified against the vendored core without this change (probe swept across all 55 golden fixtures, the default template and each outbound shape): ``` PROBE outbound/dns-legacy-keys buildErr=false PROBE-WARN ... This feature "nonIPQuery" and "blockTypes" is deprecated ... ``` While auditing the pinned core for a key it warns about or refuses that the panel still writes, this was the last unhandled one: `freedom.domainStrategy` is fixed separately (#6515), and `freedom.ipsBlocked` is already handled by the `FreedomFinalRulesReverseFix` seeder. Everything else the core prints is a *feature* notice (VMess/Trojan/shadowsocks/WS/gRPC), not a key the panel should stop writing. ## 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) - [ ] 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? `go test ./internal/database/ -run 'DNSOutboundLegacyKeys|RewriteDNSOutboundLegacyKeys' -v` - **Exact output table** (8 cases): reject/drop/skip, `blockTypes` as a list, a bare number and a comma-separated string, a missing mode defaulting to reject as the core does, existing `rules` winning over the legacy pair, a dns outbound already on rules untouched, and a non-dns outbound with the same key names untouched. - **Against the real vendored core** (`xray.ValidateOutboundConfig`, with `common/log` captured via `RegisterHandler`): the legacy outbound loads *with* the deprecation warning, the mixed one is *refused*, and after the rewrite both load with no warning and no error — so the fix is measured on the core's own verdict rather than on the panel's JSON. - **Mutation-checked**, since a migration test that passes either way proves nothing: dropping the generated rules (keeping the key deletion) fails 5 of the table cases; leaving the conversion out fails the core test on `changed=false`. - **Seeder path** over a real DB: seeds a legacy template, clears the history row, runs the seeder, asserts the stored rules and that both keys are gone; then re-seeds a legacy template and runs the full `runSeeders(false)` list to prove the history gate stops a second rewrite of a hand-edited template. Local note, same as the rest of this package's DB tests: this checkout has no C compiler, so Go was exercised with `CGO_ENABLED=0` plus an `-overlay` that stubs the one cgo-only call (`sqlite3.SQLiteConn.Backup`) — no file in this PR is replaced. The DB-path test self-skips in that build (`sqlite needs cgo`) and is the one that runs on CI. ## Screenshots / recordings N/A — no UI change. ## Breaking changes None. The seeder runs before the config is generated, and the rules it writes express the same policy the core used to derive from the legacy keys, so a converted outbound behaves as it did. Operators who never had a dns outbound are untouched. ## 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. (no C compiler here — see the note above; CI runs the cgo path) - [ ] 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:58 +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#6326
No description provided.