Skip to content

fix: validate domains before DNS dispatch#8

Merged
besnow merged 1 commit into
dev_newfrom
codex/fix-dns-errors-with-custom-dns
May 14, 2026
Merged

fix: validate domains before DNS dispatch#8
besnow merged 1 commit into
dev_newfrom
codex/fix-dns-errors-with-custom-dns

Conversation

@besnow
Copy link
Copy Markdown
Owner

@besnow besnow commented May 14, 2026

Motivation

  • 修复在开启自定义 DNS 时,非法 destination domain 进入 Xray 内置 DNS 查询链路导致的错误 app/dns: failed to pack dns query > packing Question: Name: zero length segment
  • 最小化修复,避免大改动或影响 IP、合法域名和默认 sniffing 行为。

Description

  • 新增 normalizeDNSDomain 用于域名合法性归一化与校验(trim、去尾点、长度限制、禁止空 label、禁止非法字符、label 长度与 - 边界检查)。
  • 新增 normalizeDestination,在 destination 为域名时调用 normalizeDNSDomain 并用 net.ParseAddress 覆盖合法域名地址;非法则返回失败而不继续调度。
  • DispatchDispatchLink 入口处调用 normalizeDestination,当域名非法时在 Dispatch 返回错误并记录警告,在 DispatchLink 关闭/interrupt outbound 并返回错误以避免连接泄露。
  • 将 sniffing 覆盖逻辑升级为在覆盖前用 normalizeDNSDomain 校验 sniffed domain,非法 sniffed domain 不会覆盖原始 destination,改为继续使用原 destination(不默认关闭 sniffing)。
  • 修正 core/xray/outbound.govar domainStrategy = "Asis""AsIs"(拼写大小写修正,不改变其他逻辑)。

Testing

  • 运行 go test ./core/xray/...,测试结果:通过。
  • 运行 go test ./...,测试结果:通过。

Codex Task

@besnow besnow merged commit 1568c52 into dev_new May 14, 2026
23 checks passed
@besnow besnow deleted the codex/fix-dns-errors-with-custom-dns branch May 14, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant