[PR #6918] [MERGED] fix(xray): open port 443 for private DoH servers in the DNS allow rule #6521

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

📋 Pull Request Information

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

Base: main ← Head: fix/dns-allow-rule-doh-port


📝 Commits (6)

  • d9d2dba fix(xray): open port 443 for private DoH servers in the DNS allow rule
  • 6605791 Merge remote-tracking branch 'origin/main' into pr/6918
  • f505afc fix(xray): ignore a DoH server's object port in the DNS allow rule
  • cbd8933 Merge remote-tracking branch 'origin/main' into pr/6918
  • 1d320ad style(xray): fit the DNS endpoint comments in two lines
  • 69b52c5 Merge remote-tracking branch 'origin/main' into pr/6918

📊 Changes

2 files changed (+61 additions, -17 deletions)

View changed files

📝 internal/web/service/xray_setting_dns_routing.go (+16 -17)
📝 internal/web/service/xray_setting_dns_routing_test.go (+45 -0)

📄 Description

Summary

When a DNS server is a private https:// or h2c:// address, the auto-added xui-dns-allow rule opens port 53 for it. Xray sends DoH to port 443, so the default geoip:private -> blocked rule still drops every query. This makes those two schemes default to 443.

Why

splitAddressHostPort (internal/web/service/xray_setting_dns_routing.go) strips the scheme and then defaults every address to 53. Xray-core sets the URL scheme to https for both https:// and h2c:// (app/dns/nameserver_doh.go), so with no port in the address it dials 443.

With https://10.255.255.1/dns-query as the DNS server (default template), saving gives {"ruleTag":"xui-dns-allow","ip":["10.255.255.1"],"port":"53","outboundTag":"direct"} and the core routes 10.255.255.1:443 to blocked. A DoH lookup through a SOCKS inbound then logs taking detour [blocked] for [tcp:10.255.255.1:443] and fails. The DNS form hides the port field for encrypted addresses, so a panel user can't work around it there. This hits self-hosted DoH resolvers on a LAN (AdGuard Home, Pi-hole with DoH).

The +local forms query outside routing, so they keep 53 as before; an explicit port still wins.

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?

  • TestEnsureDnsServerRouting_RemoteDohUsesHttpsPort: https:// and h2c:// without a port go into a 443 rule, https://...:8443 keeps 8443. It fails on main.
  • go test ./... (50 packages ok), go vet ./internal/web/service/.
  • Panel built from main and from this branch, DNS servers https://10.255.255.1/dns-query and h2c://10.255.255.2/dns-query, then POST /panel/api/xray/routeTest:
    • main: rule port 53; 10.255.255.1:443 and 10.255.255.2:443 -> blocked.
    • this branch: rule port 443; both -> direct.

Breaking changes

None.

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.

golangci-lint run ./internal/web/service/...: 0 issues.


🔄 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/6918 **Author:** [@jayhemnani9910](https://github.com/jayhemnani9910) **Created:** 10/24/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/dns-allow-rule-doh-port` --- ### 📝 Commits (6) - [`d9d2dba`](https://github.com/MHSanaei/3x-ui/commit/d9d2dba8e3dfac255f0fd9c9a06308ffddbbfca0) fix(xray): open port 443 for private DoH servers in the DNS allow rule - [`6605791`](https://github.com/MHSanaei/3x-ui/commit/6605791bf28195422c4ddf9307dc450e436339a0) Merge remote-tracking branch 'origin/main' into pr/6918 - [`f505afc`](https://github.com/MHSanaei/3x-ui/commit/f505afc090c08e6302f312573e3da0b67bab1035) fix(xray): ignore a DoH server's object port in the DNS allow rule - [`cbd8933`](https://github.com/MHSanaei/3x-ui/commit/cbd89332948463675edc30498e855e2d8a339b39) Merge remote-tracking branch 'origin/main' into pr/6918 - [`1d320ad`](https://github.com/MHSanaei/3x-ui/commit/1d320adee658dce1ea8cb8371eb8e16c7aa70c32) style(xray): fit the DNS endpoint comments in two lines - [`69b52c5`](https://github.com/MHSanaei/3x-ui/commit/69b52c5d88c81714d04223fbba3c2e572d77053f) Merge remote-tracking branch 'origin/main' into pr/6918 ### 📊 Changes **2 files changed** (+61 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/xray_setting_dns_routing.go` (+16 -17) 📝 `internal/web/service/xray_setting_dns_routing_test.go` (+45 -0) </details> ### 📄 Description ## Summary When a DNS server is a private `https://` or `h2c://` address, the auto-added `xui-dns-allow` rule opens port 53 for it. Xray sends DoH to port 443, so the default `geoip:private -> blocked` rule still drops every query. This makes those two schemes default to 443. ## Why `splitAddressHostPort` (`internal/web/service/xray_setting_dns_routing.go`) strips the scheme and then defaults every address to 53. Xray-core sets the URL scheme to `https` for both `https://` and `h2c://` (`app/dns/nameserver_doh.go`), so with no port in the address it dials 443. With `https://10.255.255.1/dns-query` as the DNS server (default template), saving gives `{"ruleTag":"xui-dns-allow","ip":["10.255.255.1"],"port":"53","outboundTag":"direct"}` and the core routes `10.255.255.1:443` to `blocked`. A DoH lookup through a SOCKS inbound then logs `taking detour [blocked] for [tcp:10.255.255.1:443]` and fails. The DNS form hides the port field for encrypted addresses, so a panel user can't work around it there. This hits self-hosted DoH resolvers on a LAN (AdGuard Home, Pi-hole with DoH). The `+local` forms query outside routing, so they keep 53 as before; an explicit port still wins. ## 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 - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? - `TestEnsureDnsServerRouting_RemoteDohUsesHttpsPort`: `https://` and `h2c://` without a port go into a 443 rule, `https://...:8443` keeps 8443. It fails on main. - `go test ./...` (50 packages ok), `go vet ./internal/web/service/`. - Panel built from main and from this branch, DNS servers `https://10.255.255.1/dns-query` and `h2c://10.255.255.2/dns-query`, then `POST /panel/api/xray/routeTest`: - main: rule port 53; `10.255.255.1:443` and `10.255.255.2:443` -> `blocked`. - this branch: rule port 443; both -> `direct`. ## Breaking changes None. ## 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. - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. `golangci-lint run ./internal/web/service/...`: 0 issues. --- <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:22 +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#6521
No description provided.