[GH-ISSUE #5920] [Bug]: Incorrect DNS Port Configuration for DoH Presets #4107

Closed
opened 2026-10-31 20:37:13 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @parsa-fathi on GitHub (Jul 13, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5920

Describe the bug

Bug Report: Incorrect DNS Port Configuration for DoH Presets

Description

In the panel's Preset DNS section, the predefined DNS records for DNS over HTTPS (DoH) are configured with port 53.

According to the Xray Core documentation, the port field should not be used for DoH, DoHL, or DoQ modes. The port must be specified directly inside the URL if a non-standard port is required.

Steps to Reproduce

  1. Open the panel.
  2. Navigate to the Preset DNS section.
  3. Check the predefined DNS entries that use the DoH mode.
  4. Observe that these records contain port: 53.

Expected Behavior

For DoH DNS entries:

  • The port field should be omitted.
  • If a custom port is required, it should be included in the DoH URL.

Example:

{
  "address": "https://dns.example.com/dns-query"
}

or for a custom port:

{
  "address": "https://dns.example.com:8443/dns-query"
}

Actual Behavior

DoH preset entries are generated with:

{
  "address": "https://dns.example.com/dns-query",
  "port": 53
}

which is invalid according to Xray Core documentation.

Reference

https://xtls.github.io/en/config/dns.html#dnsobject
Xray Core documentation:

port: number
DNS server port, e.g., 53. Defaults to 53 if omitted. This item is invalid when using DOH, DOHL, or DOQL modes; non-standard ports should be specified in the URL.

Impact

This may cause invalid DNS configuration generation or unexpected behavior when using DoH-based DNS resolvers.

How to reproduce the problem

  1. Open the panel.
  2. Navigate to the Preset DNS section.
  3. Check the predefined DNS entries that use the DoH mode.
  4. Observe that these records contain port: 53.

Expected behavior

No response

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.5.0

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu26

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @parsa-fathi on GitHub (Jul 13, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5920 ### Describe the bug # Bug Report: Incorrect DNS Port Configuration for DoH Presets ## Description In the panel's **Preset DNS** section, the predefined DNS records for **DNS over HTTPS (DoH)** are configured with port `53`. According to the Xray Core documentation, the `port` field should not be used for DoH, DoHL, or DoQ modes. The port must be specified directly inside the URL if a non-standard port is required. ## Steps to Reproduce 1. Open the panel. 2. Navigate to the **Preset DNS** section. 3. Check the predefined DNS entries that use the **DoH** mode. 4. Observe that these records contain `port: 53`. ## Expected Behavior For DoH DNS entries: * The `port` field should be omitted. * If a custom port is required, it should be included in the DoH URL. Example: ```json { "address": "https://dns.example.com/dns-query" } ``` or for a custom port: ```json { "address": "https://dns.example.com:8443/dns-query" } ``` ## Actual Behavior DoH preset entries are generated with: ```json { "address": "https://dns.example.com/dns-query", "port": 53 } ``` which is invalid according to Xray Core documentation. ## Reference https://xtls.github.io/en/config/dns.html#dnsobject Xray Core documentation: > `port: number` > DNS server port, e.g., 53. Defaults to 53 if omitted. This item is invalid when using DOH, DOHL, or DOQL modes; non-standard ports should be specified in the URL. ## Impact This may cause invalid DNS configuration generation or unexpected behavior when using DoH-based DNS resolvers. ### How to reproduce the problem 1. Open the panel. 2. Navigate to the **Preset DNS** section. 3. Check the predefined DNS entries that use the **DoH** mode. 4. Observe that these records contain `port: 53`. ### Expected behavior _No response_ ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.5.0 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu26 ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:37:13 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jul 13, 2026):

Confirmed as a real defect, but not quite where the reproduction steps point — clicking "Install" on a DoH/DoQ preset does not itself attach a port. I traced the full path from preset to saved config.

What "Install" actually produces: PRESETS in frontend/src/pages/xray/dns/DnsPresetsModal.tsx (lines 37-66) stores DoH/DoQ entries as bare address strings, e.g. 'https://cloudflare-dns.com/dns-query'. onPresetInstall in frontend/src/pages/xray/dns/DnsTab.tsx:180-185 copies that string array straight into dns.servers with no transformation, so right after clicking "Install" the entry is just "https://cloudflare-dns.com/dns-query" — no port key, matching the "Expected Behavior" in this report.

Where port: 53 actually gets attached: as soon as a DoH/DoQ entry becomes an object instead of a bare string, port is force-defaulted to 53 with no check on the address scheme, in two places:

  • frontend/src/schemas/dns.ts:19 — DnsServerObjectInnerSchema declares port: PortSchema.default(53). Any object-form server entry parsed through this schema gets port: 53 injected even when the source JSON omits it. The repo's own test data proves this: fixture frontend/src/test/golden/fixtures/dns/full.json (lines 32-40) has a quic+local://dns.adguard.com (DoQ) entry with no port key, but the corresponding parsed snapshot frontend/src/test/__snapshots__/dns.test.ts.snap (line 44) shows "port": 53 added to that same entry.
  • frontend/src/pages/xray/dns/DnsServerModal.tsx, function valuesToWire (lines 93-127): it always sets out.port = values.port whenever any other field differs from its default (tag, domains, queryStrategy, skipFallback, clientIP, etc.), regardless of whether address starts with https://, https+local://, or quic+local://. Concrete repro: install a DoH/DoQ preset, open "Edit" on that row, change any other field (e.g. add a tag), confirm — the saved entry becomes {"address": "https://.../dns-query", "port": 53, ...}, matching this report's "Actual Behavior" exactly.

Title: DNS server schema and edit form force-default port: 53 on DoH/DoQ addresses regardless of URI scheme
Severity: Low
Category: Correctness
Why this matters: per the Xray-core docs you cited, port is invalid for DOH/DOHL/DOQL entries and should be embedded in the URL instead. Once a DoH/DoQ entry (preset-installed or manually added) is edited with any other non-default field, the panel writes a port field onto it that shouldn't be there. I did not verify xray-core's actual tolerance for a superfluous port next to a DoH/DoQ address (hard rejection vs. silently ignored field), so I can't confirm whether this breaks DNS resolution outright or is a harmless no-op — the severity above reflects spec non-compliance, not a confirmed runtime failure.
Recommendation: make the port default conditional on the address scheme in both places — skip the .default(53) fill in DnsServerObjectInnerSchema (frontend/src/schemas/dns.ts:19) and skip setting out.port in valuesToWire (frontend/src/pages/xray/dns/DnsServerModal.tsx:110-126) when address starts with https://, https+local://, or quic+local://. No change is needed in DnsPresetsModal.tsx / DnsTab.tsx, since the plain-install path already stays string-only.
Example:

// frontend/src/schemas/dns.ts:17-19
export const DnsServerObjectInnerSchema = z.object({
  address: z.string(),
  port: PortSchema.default(53), // unconditional — no scheme check against `address`

Confidence: high on the mechanism described above (verified directly against source and the repo's own golden-fixture/snapshot test). Lower on real-world impact at the Xray-core runtime layer, which I did not inspect in this pass.

@MHSanaei for a fix decision.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4954247602 --> @github-actions[bot] commented on GitHub (Jul 13, 2026): Confirmed as a real defect, but not quite where the reproduction steps point — clicking "Install" on a DoH/DoQ preset does not itself attach a port. I traced the full path from preset to saved config. **What "Install" actually produces:** `PRESETS` in `frontend/src/pages/xray/dns/DnsPresetsModal.tsx` (lines 37-66) stores DoH/DoQ entries as bare address strings, e.g. `'https://cloudflare-dns.com/dns-query'`. `onPresetInstall` in `frontend/src/pages/xray/dns/DnsTab.tsx:180-185` copies that string array straight into `dns.servers` with no transformation, so right after clicking "Install" the entry is just `"https://cloudflare-dns.com/dns-query"` — no `port` key, matching the "Expected Behavior" in this report. **Where `port: 53` actually gets attached:** as soon as a DoH/DoQ entry becomes an **object** instead of a bare string, `port` is force-defaulted to 53 with no check on the address scheme, in two places: - `frontend/src/schemas/dns.ts:19` — `DnsServerObjectInnerSchema` declares `port: PortSchema.default(53)`. Any object-form server entry parsed through this schema gets `port: 53` injected even when the source JSON omits it. The repo's own test data proves this: fixture `frontend/src/test/golden/fixtures/dns/full.json` (lines 32-40) has a `quic+local://dns.adguard.com` (DoQ) entry with no `port` key, but the corresponding parsed snapshot `frontend/src/test/__snapshots__/dns.test.ts.snap` (line 44) shows `"port": 53` added to that same entry. - `frontend/src/pages/xray/dns/DnsServerModal.tsx`, function `valuesToWire` (lines 93-127): it always sets `out.port = values.port` whenever any other field differs from its default (tag, domains, queryStrategy, skipFallback, clientIP, etc.), regardless of whether `address` starts with `https://`, `https+local://`, or `quic+local://`. Concrete repro: install a DoH/DoQ preset, open "Edit" on that row, change any other field (e.g. add a tag), confirm — the saved entry becomes `{"address": "https://.../dns-query", "port": 53, ...}`, matching this report's "Actual Behavior" exactly. Title: DNS server schema and edit form force-default `port: 53` on DoH/DoQ addresses regardless of URI scheme Severity: Low Category: Correctness Why this matters: per the Xray-core docs you cited, `port` is invalid for DOH/DOHL/DOQL entries and should be embedded in the URL instead. Once a DoH/DoQ entry (preset-installed or manually added) is edited with any other non-default field, the panel writes a `port` field onto it that shouldn't be there. I did not verify xray-core's actual tolerance for a superfluous `port` next to a DoH/DoQ address (hard rejection vs. silently ignored field), so I can't confirm whether this breaks DNS resolution outright or is a harmless no-op — the severity above reflects spec non-compliance, not a confirmed runtime failure. Recommendation: make the `port` default conditional on the `address` scheme in both places — skip the `.default(53)` fill in `DnsServerObjectInnerSchema` (`frontend/src/schemas/dns.ts:19`) and skip setting `out.port` in `valuesToWire` (`frontend/src/pages/xray/dns/DnsServerModal.tsx:110-126`) when `address` starts with `https://`, `https+local://`, or `quic+local://`. No change is needed in `DnsPresetsModal.tsx` / `DnsTab.tsx`, since the plain-install path already stays string-only. Example: ``` // frontend/src/schemas/dns.ts:17-19 export const DnsServerObjectInnerSchema = z.object({ address: z.string(), port: PortSchema.default(53), // unconditional — no scheme check against `address` ``` Confidence: high on the mechanism described above (verified directly against source and the repo's own golden-fixture/snapshot test). Lower on real-world impact at the Xray-core runtime layer, which I did not inspect in this pass. @MHSanaei for a fix decision. *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@mvanhorn commented on GitHub (Jul 14, 2026):

Opened #5950 to address this. It stops the panel from writing port: 53 onto DoH / DoH-Local / DoQ (and h2c) DNS server entries, defaulting the port only for non-encrypted schemes. Includes unit tests and a regenerated snapshot.

<!-- gh-comment-id:4965790374 --> @mvanhorn commented on GitHub (Jul 14, 2026): Opened #5950 to address this. It stops the panel from writing `port: 53` onto DoH / DoH-Local / DoQ (and h2c) DNS server entries, defaulting the port only for non-encrypted schemes. Includes unit tests and a regenerated snapshot.
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#4107
No description provided.