[PR #6868] [MERGED] feat(sub): opt-in dns and sniffer from remote Clash rules #6490

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6868
Author: @yelloduxx
Created: 10/18/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei

Base: main ← Head: feat/clash-remote-dns


📝 Commits (5)

  • 723b4b8 feat(sub): opt-in dns and sniffer from remote Clash rules
  • 78b0a2c feat(settings): add the Clash remote DNS switch
  • 89414e6 fix(sub): skip a malformed remote dns or sniffer instead of the whole routing
  • 5df319e docs(api): sync openapi.json with subClashRemoteDNS
  • 97b3f1d test(frontend): outlast the AntD Form error debounce in component teardown

📊 Changes

44 files changed (+355 additions, -46 deletions)

View changed files

📝 docs/public/openapi.json (+8 -0)
📝 frontend/public/openapi.json (+8 -0)
📝 frontend/src/generated/examples.ts (+2 -0)
📝 frontend/src/generated/schemas.ts (+8 -0)
📝 frontend/src/generated/types.ts (+2 -0)
📝 frontend/src/generated/zod.ts (+2 -0)
📝 frontend/src/models/setting.ts (+1 -0)
📝 frontend/src/pages/settings/SubscriptionGeneralTab.tsx (+10 -0)
📝 frontend/src/schemas/setting.ts (+1 -0)
📝 frontend/src/test/setup.components.ts (+6 -0)
📝 frontend/src/test/subscription-general-tab.test.tsx (+23 -0)
📝 internal/sub/clash_external_shadowsocks_test.go (+1 -1)
📝 internal/sub/clash_external_vless_test.go (+1 -1)
📝 internal/sub/clash_info_node_test.go (+4 -4)
➕ internal/sub/clash_remote_dns_test.go (+162 -0)
📝 internal/sub/clash_service.go (+45 -19)
📝 internal/sub/clash_service_test.go (+1 -1)
📝 internal/sub/controller.go (+6 -1)
📝 internal/sub/external_config_test.go (+1 -1)
📝 internal/sub/external_only_sub_test.go (+1 -1)

...and 24 more files

📄 Description

Summary

Adds a "Use DNS from remote rules" switch (subClashRemoteDNS, off by default) to Settings → Subscription → Clash / Mihomo. When the global routing rules field holds a URL and the switch is on, the panel also takes the dns and sniffer sections from the remote document.

Why

Public Mihomo templates such as roscomvpn ship rules, rule-providers and proxy-groups together with a dns block that those rules depend on (fake-ip ranges, nameserver policy, fallback filters). Pasting the template inline keeps its dns, because mergeClashRulesYAML copies every key. Pointing the field at the template URL drops it, because mergeRemoteClashRules only accepts the route-graph keys. The generated subscription then has no dns section, and clients fall back to their built-in resolvers. A URL is the form that stays current without editing the panel, so admins who want the template's DNS today have to give up auto-refresh.

The switch is opt-in because a remote dns block controls where clients send every lookup. It should come only from a source the admin trusts.

Refs #6363, #6671 (other requests to take more from the remote Clash source).

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 build ./..., go vet ./..., go test ./internal/sub/... ./internal/web/....
  • New internal/sub/clash_remote_dns_test.go:
    • with the switch off, remote dns/sniffer are ignored, as before;
    • with it on, they replace the base sections;
    • a null or non-map dns or sniffer is skipped, and the remote routing still applies;
    • a remote document with only dns and no rules, groups or providers is still rejected when fetched;
    • TestClashSubscriptionRemoteDNSFollowsSetting builds a full Clash subscription through the controller and checks the dns section follows the setting.
  • setting_clash_test.go covers the default and the getter. subscription-general-tab.test.tsx covers the switch.
  • Frontend: npm run gen (no diff afterwards), npm run lint, npm run typecheck, npm run build, npx vitest (unit and components).
  • Manual: built the binary for linux/amd64 and ran it on a production panel with Xray 26.10.10. Set the routing rules field to https://raw.githubusercontent.com/hydraponique/roscomvpn-routing/main/MIHOMO/default.yaml and turned the switch on. The Clash subscription then carried the template's dns and sniffer sections, the generated proxies and all RULE-SET rules.

Screenshots / recordings

The new switch under the routing rules field (en-US):

clash-remote-dns-switch

Breaking changes

None. The switch defaults to off, and the subscription output is unchanged until an admin turns it on. A malformed remote dns or sniffer is skipped rather than rejected, so it never costs a template its routing.

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. (N/A: the docs don't describe remote routing rules yet; the setting carries its own description.)
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🤖 Generated with Claude Code


🔄 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/6868 **Author:** [@yelloduxx](https://github.com/yelloduxx) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/clash-remote-dns` --- ### 📝 Commits (5) - [`723b4b8`](https://github.com/MHSanaei/3x-ui/commit/723b4b868268115f96af59a9c84cfaf225f2cc40) feat(sub): opt-in dns and sniffer from remote Clash rules - [`78b0a2c`](https://github.com/MHSanaei/3x-ui/commit/78b0a2c4d1583df0f521bea1955e9ca4761f8d88) feat(settings): add the Clash remote DNS switch - [`89414e6`](https://github.com/MHSanaei/3x-ui/commit/89414e6c405d48774e3a077aa3fb8e3edff14a20) fix(sub): skip a malformed remote dns or sniffer instead of the whole routing - [`5df319e`](https://github.com/MHSanaei/3x-ui/commit/5df319e13d645519fb34f5bea48042f69d4fbc9e) docs(api): sync openapi.json with subClashRemoteDNS - [`97b3f1d`](https://github.com/MHSanaei/3x-ui/commit/97b3f1dc2975374fbe810470a4f10b4a78e6273e) test(frontend): outlast the AntD Form error debounce in component teardown ### 📊 Changes **44 files changed** (+355 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `docs/public/openapi.json` (+8 -0) 📝 `frontend/public/openapi.json` (+8 -0) 📝 `frontend/src/generated/examples.ts` (+2 -0) 📝 `frontend/src/generated/schemas.ts` (+8 -0) 📝 `frontend/src/generated/types.ts` (+2 -0) 📝 `frontend/src/generated/zod.ts` (+2 -0) 📝 `frontend/src/models/setting.ts` (+1 -0) 📝 `frontend/src/pages/settings/SubscriptionGeneralTab.tsx` (+10 -0) 📝 `frontend/src/schemas/setting.ts` (+1 -0) 📝 `frontend/src/test/setup.components.ts` (+6 -0) 📝 `frontend/src/test/subscription-general-tab.test.tsx` (+23 -0) 📝 `internal/sub/clash_external_shadowsocks_test.go` (+1 -1) 📝 `internal/sub/clash_external_vless_test.go` (+1 -1) 📝 `internal/sub/clash_info_node_test.go` (+4 -4) ➕ `internal/sub/clash_remote_dns_test.go` (+162 -0) 📝 `internal/sub/clash_service.go` (+45 -19) 📝 `internal/sub/clash_service_test.go` (+1 -1) 📝 `internal/sub/controller.go` (+6 -1) 📝 `internal/sub/external_config_test.go` (+1 -1) 📝 `internal/sub/external_only_sub_test.go` (+1 -1) _...and 24 more files_ </details> ### 📄 Description ## Summary Adds a "Use DNS from remote rules" switch (`subClashRemoteDNS`, off by default) to Settings → Subscription → Clash / Mihomo. When the global routing rules field holds a URL and the switch is on, the panel also takes the `dns` and `sniffer` sections from the remote document. ## Why Public Mihomo templates such as roscomvpn ship `rules`, `rule-providers` and `proxy-groups` together with a `dns` block that those rules depend on (fake-ip ranges, nameserver policy, fallback filters). Pasting the template inline keeps its `dns`, because `mergeClashRulesYAML` copies every key. Pointing the field at the template URL drops it, because `mergeRemoteClashRules` only accepts the route-graph keys. The generated subscription then has no `dns` section, and clients fall back to their built-in resolvers. A URL is the form that stays current without editing the panel, so admins who want the template's DNS today have to give up auto-refresh. The switch is opt-in because a remote `dns` block controls where clients send every lookup. It should come only from a source the admin trusts. Refs #6363, #6671 (other requests to take more from the remote Clash source). ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] 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? - `go build ./...`, `go vet ./...`, `go test ./internal/sub/... ./internal/web/...`. - New `internal/sub/clash_remote_dns_test.go`: - with the switch off, remote `dns`/`sniffer` are ignored, as before; - with it on, they replace the base sections; - a null or non-map `dns` or `sniffer` is skipped, and the remote routing still applies; - a remote document with only `dns` and no rules, groups or providers is still rejected when fetched; - `TestClashSubscriptionRemoteDNSFollowsSetting` builds a full Clash subscription through the controller and checks the `dns` section follows the setting. - `setting_clash_test.go` covers the default and the getter. `subscription-general-tab.test.tsx` covers the switch. - Frontend: `npm run gen` (no diff afterwards), `npm run lint`, `npm run typecheck`, `npm run build`, `npx vitest` (unit and components). - Manual: built the binary for linux/amd64 and ran it on a production panel with Xray 26.10.10. Set the routing rules field to `https://raw.githubusercontent.com/hydraponique/roscomvpn-routing/main/MIHOMO/default.yaml` and turned the switch on. The Clash subscription then carried the template's `dns` and `sniffer` sections, the generated proxies and all `RULE-SET` rules. ## Screenshots / recordings The new switch under the routing rules field (en-US): <img width="800" height="600" alt="clash-remote-dns-switch" src="https://github.com/user-attachments/assets/40a81175-4d22-4011-8102-2f96fbe26e5b" /> ## Breaking changes None. The switch defaults to off, and the subscription output is unchanged until an admin turns it on. A malformed remote `dns` or `sniffer` is skipped rather than rejected, so it never costs a template its routing. ## 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. - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. (N/A: the docs don't describe remote routing rules yet; the setting carries its own description.) - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:09:08 +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#6490
No description provided.