[PR #5774] [MERGED] fix(routing): allow dns.servers on private IPs past the geoip:private block rule #5982

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5774
Author: @volov-de
Created: 7/3/2026
Status: ✅ Merged
Merged: 7/8/2026
Merged by: @MHSanaei

Base: main ← Head: fix/dns-servers-private-ip-routing


📝 Commits (4)

  • 8277106 fix(routing): allow dns.servers on private IPs past the geoip:private block rule
  • 5587124 fix(routing): scope the DNS allow-rule to its port, guard against reorder/UI drift
  • da23ecd fix: avoid size-computation overflow in allocation hint
  • cedf508 Merge branch 'main' into fix/dns-servers-private-ip-routing

📊 Changes

3 files changed (+800 additions, -0 deletions)

View changed files

📝 internal/web/service/xray_setting.go (+3 -0)
➕ internal/web/service/xray_setting_dns_routing.go (+386 -0)
➕ internal/web/service/xray_setting_dns_routing_test.go (+411 -0)

📄 Description

Summary

Auto-generates a direct allow-rule for any private/internal IP found in dns.servers, inserted immediately before the panel's default geoip:private -> blocked routing rule, so Xray's own DNS lookups no longer get silently dropped by that rule.

Why

Closes #5773.

Xray's own DNS client traffic is dispatched through the same routing table as proxied client traffic. When dns.servers points at a private IP (e.g. a self-hosted AdGuard Home / Pi-hole reachable on the same Docker network as Xray — a common self-hosted setup) and the panel's default geoip:private block rule is active, Xray's own DNS lookups get silently dropped by that rule. Xray then falls back to dialing destinations by raw hostname once its internal DNS attempt times out (~4s), so proxied connections still work — just with a multi-second stall added to every new domain-based connection, with no error surfaced anywhere. Root-caused with an Xray debug-log trace, details in the linked issue.

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 EnsureDnsServerRouting (internal/web/service/xray_setting_dns_routing.go, mirrors the existing EnsureStatsRouting hoist) is wired into SaveXraySetting right after EnsureStatsRouting.
  • internal/web/service/xray_setting_dns_routing_test.go — 12 new cases: no-op paths (no dns.servers / public IP / no block rule present), correct insertion position, both server-entry shapes (bare string and {address, port, ...} object), scheme/port/path stripping (including bracketed IPv6), skipping special/domain addresses (localhost, fakedns, plain hostnames), idempotency across repeated saves, in-place update when the server set changes, rule removal once no longer needed, and leaving hand-authored rules with extra matchers untouched.
  • go test ./internal/web/service/... — all packages pass, no regressions.
  • go vet ./internal/web/service/... and gofmt -l on the changed files — clean.
  • go build ./internal/web/service/... — clean (built via a golang:1.26 container; couldn't run go build ./... for the full binary locally since internal/web/web.go's go:embed all:dist needs a built frontend, which is unrelated to this change).
  • Manually verified against the real-world repro from the issue (VLESS+Reality inbound + AdGuard Home on the same Docker network): before the fix, every new-domain connection stalled ~4s; after applying the equivalent rule by hand (and now via this change), connections complete in tens of ms.

Screenshots / recordings

N/A — backend-only change, no UI.

Breaking changes

None. The generated rule is only added when both a private dns.servers IP and an existing geoip:private block rule are present, and is kept in sync automatically; nothing changes for setups that don't have this combination.

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 caveat above: built/tested the affected package directly rather than the full binary, since the frontend isn't part of this change)
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass. — N/A, no frontend changes.
  • I updated the Wiki / README / API docs if user-facing behavior changed. — N/A, this is an internal, automatic fix; there was no prior doc describing the old (buggy) behavior to update.
  • 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/5774 **Author:** [@volov-de](https://github.com/volov-de) **Created:** 7/3/2026 **Status:** ✅ Merged **Merged:** 7/8/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/dns-servers-private-ip-routing` --- ### 📝 Commits (4) - [`8277106`](https://github.com/MHSanaei/3x-ui/commit/8277106afad733bee6040c9b26a62fbc6da092be) fix(routing): allow dns.servers on private IPs past the geoip:private block rule - [`5587124`](https://github.com/MHSanaei/3x-ui/commit/5587124a130d5cea1b53d10670260e31e0bcbf58) fix(routing): scope the DNS allow-rule to its port, guard against reorder/UI drift - [`da23ecd`](https://github.com/MHSanaei/3x-ui/commit/da23ecdd9a82a7b10ec6ff29eec6bd0ccbd2daf7) fix: avoid size-computation overflow in allocation hint - [`cedf508`](https://github.com/MHSanaei/3x-ui/commit/cedf508cb4f188bfab4f3bbed8725e3ee8c95b27) Merge branch 'main' into fix/dns-servers-private-ip-routing ### 📊 Changes **3 files changed** (+800 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/xray_setting.go` (+3 -0) ➕ `internal/web/service/xray_setting_dns_routing.go` (+386 -0) ➕ `internal/web/service/xray_setting_dns_routing_test.go` (+411 -0) </details> ### 📄 Description ## Summary Auto-generates a `direct` allow-rule for any private/internal IP found in `dns.servers`, inserted immediately before the panel's default `geoip:private -> blocked` routing rule, so Xray's own DNS lookups no longer get silently dropped by that rule. ## Why Closes #5773. Xray's own DNS client traffic is dispatched through the same routing table as proxied client traffic. When `dns.servers` points at a private IP (e.g. a self-hosted AdGuard Home / Pi-hole reachable on the same Docker network as Xray — a common self-hosted setup) and the panel's default `geoip:private` block rule is active, Xray's own DNS lookups get silently dropped by that rule. Xray then falls back to dialing destinations by raw hostname once its internal DNS attempt times out (~4s), so proxied connections still work — just with a multi-second stall added to every new domain-based connection, with no error surfaced anywhere. Root-caused with an Xray debug-log trace, details in the linked issue. ## 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? - New `EnsureDnsServerRouting` (`internal/web/service/xray_setting_dns_routing.go`, mirrors the existing `EnsureStatsRouting` hoist) is wired into `SaveXraySetting` right after `EnsureStatsRouting`. - `internal/web/service/xray_setting_dns_routing_test.go` — 12 new cases: no-op paths (no `dns.servers` / public IP / no block rule present), correct insertion position, both server-entry shapes (bare string and `{address, port, ...}` object), scheme/port/path stripping (including bracketed IPv6), skipping special/domain addresses (`localhost`, `fakedns`, plain hostnames), idempotency across repeated saves, in-place update when the server set changes, rule removal once no longer needed, and leaving hand-authored rules with extra matchers untouched. - `go test ./internal/web/service/...` — all packages pass, no regressions. - `go vet ./internal/web/service/...` and `gofmt -l` on the changed files — clean. - `go build ./internal/web/service/...` — clean (built via a `golang:1.26` container; couldn't run `go build ./...` for the full binary locally since `internal/web/web.go`'s `go:embed all:dist` needs a built frontend, which is unrelated to this change). - Manually verified against the real-world repro from the issue (VLESS+Reality inbound + AdGuard Home on the same Docker network): before the fix, every new-domain connection stalled ~4s; after applying the equivalent rule by hand (and now via this change), connections complete in tens of ms. ## Screenshots / recordings N/A — backend-only change, no UI. ## Breaking changes None. The generated rule is only added when both a private `dns.servers` IP and an existing `geoip:private` block rule are present, and is kept in sync automatically; nothing changes for setups that don't have this combination. ## 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 caveat above: built/tested the affected package directly rather than the full binary, since the frontend isn't part of this change) - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. — N/A, no frontend changes. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. — N/A, this is an internal, automatic fix; there was no prior doc describing the old (buggy) behavior to update. - [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:05:31 +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#5982
No description provided.