sing-box icon indicating copy to clipboard operation
sing-box copied to clipboard

Removing trailing dot in FQDN with DNS type local causes incorrect resolution via search domains

Open clsv opened this issue 1 year ago • 4 comments

Operating system

Linux

System version

Debian testing, kernel 6.16.11

Installation type

Original sing-box Command Line

If you are using a graphical client, please provide the version of the client.

No response

Version

sing-box version 1.12.10

Environment: go1.25.3 linux/amd64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale
Revision: 444f45481023f6e8851dbcb294f744629efd0448
CGO: disabled

Description

Hello,

I noticed in the code at dns/client_log.go#L51 that the trailing dot in fully qualified domain names (FQDNs) is removed. According to DNS standards (RFC 1034, RFC 1035), the trailing dot explicitly marks the root of the DNS hierarchy and ensures that the domain name is fully qualified and absolute. This trailing dot is important for disambiguation and precise DNS resolution.

In my case, this removal causes the system to start using the search domain suffixes from resolv.conf. Because the name no longer ends with the absolute trailing dot, it is treated as relative, leading to unintended domain expansions and potential resolution delays or failures.

Additionally, if one of the search domains responds to wildcard (*) queries, the resolution process will break completely because the wildcard will catch arbitrary queries, causing unexpected and incorrect DNS responses.

Reproduction

config.json

{
  "log": {
    "level": "debug"

  },
  "dns": {
    "servers": [
      {
        "type": "local",
        "tag": "local-dns",
      }
    ]
  },
  "inbounds": [
    {
      "type": "socks",
      "tag": "socks-in",
      "listen": "0.0.0.0",
      "listen_port": 1080
    }
  ],
  "outbounds": [
    {
      "type": "vless",
      "tag": "vless",
      "server": "example.server.com.",
      "server_port": 443,
      "uuid": "791eab15-6736-49f9-806c-b130f8c83ba6",
      "flow": "xtls-rprx-vision",
      "network": "tcp",
      "tls": {
        "enabled": true,
        "disable_sni": false,
        "server_name": "yahoo.com",
        "insecure": false,
        "fragment": true,
        "record_fragment": true,
        "alpn": [
          "h3",
          "h2"
        ],
        "reality": {
          "enabled": true,
          "public_key": "",
          "short_id": "a0030945"
        },
        "utls": {
          "enabled": true,
          "fingerprint": "chrome"
        }
      },
      "multiplex": {
        "enabled": false
      }
    },
  ],
  "route": {
    "rules": [
      {
        "inbound": ["socks-in"],
        "outbound": "vless"
      }
    ],
    "auto_detect_interface": true,
    "default_domain_resolver": "local-dns"
  }
}

/etc/resolv.conf

nameserver 127.0.0.53
options edns0 trust-ad
search lan domain.tech cluster.local lan

Logs

ERROR[0005] [3018697143 5.4s] connection: open connection to <IP>:80 using outbound/vless[vless]: dial tcp 10.3.25.246:443: i/o timeout

Supporter

Integrity requirements

  • [x] I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
  • [x] I confirm that I have provided the server and client configuration files and process that can be reproduced locally, instead of a complicated client configuration file that has been stripped of sensitive data.
  • [x] I confirm that I have provided the simplest configuration that can be used to reproduce the error I reported, instead of depending on remote servers, TUN, graphical interface clients, or other closed-source software.
  • [x] I confirm that I have provided the complete configuration files and logs, rather than just providing parts I think are useful out of confidence in my own intelligence.

clsv avatar Oct 16 '25 12:10 clsv

From the logs you uploaded in Issues, the outbound's IP has been resolved successfully. It doesn't seem like a dns problem. Instead, your client sent a request with an unspecified IP to sing-box.

daminit avatar Oct 16 '25 12:10 daminit

From the logs you uploaded in Issues, the outbound's IP has been resolved successfully. It doesn't seem like a dns problem. Instead, your client sent a request with an unspecified IP to sing-box.

The main issue is that I specify the domain with a trailing dot, assuming that the search option should not be used. However, the code removes this dot for some reason.

I had to work around the problem in the following way...

  "dns": {
    "servers": [{
        "type": "udp", 
        "server": "127.0.0.53",
        "tag": "local"
    }]
  },

Commenting out this line resolved the problem.

func FqdnToDomain(fqdn string) string {
	if dns.IsFqdn(fqdn) {
		// return fqdn[:len(fqdn)-1]
	}
	return fqdn
}

clsv avatar Oct 16 '25 12:10 clsv

Please check to see if this issue has been fixed in both main-next and dev-next.

nekohasekai avatar Oct 16 '25 13:10 nekohasekai

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Dec 16 '25 02:12 github-actions[bot]