docmirror/dev-sidecar · warning

域名 ${rOptions.hostname} 在dns中未配置,但使用了 sni: ${rOptions.server

Error message

域名 ${rOptions.hostname} 在dns中未配置,但使用了 sni: ${rOptions.servername},然而DNS服务管理中,并未指定SNI默认使用的DNS。

What it means

During request setup, if the target domain has no DNS mapping in dnsMap but the request carries an SNI servername (typical for HTTPS), the handler needs a DNS implementation for the lookup. If the special `dnsMap.ForSNI` default DNS is also absent, no lookup function can be built and this warning is logged; the request proceeds without custom DNS (falls back to system DNS).

Source

Thrown at packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js:126

          }
        }
        onFree()

        function onFree () {
          url = `${rOptions.method} ➜ ${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}`
          const start = Date.now()
          log.info('发起代理请求:', url, (rOptions.servername ? `, sni: ${rOptions.servername}` : ''), ', headers:', jsonApi.stringify2(rOptions.headers))

          const isDnsIntercept = {}
          if (dnsConfig && dnsConfig.dnsMap) {
            let dnsAndFamily = DnsUtil.getDNSAndFamily(dnsConfig, rOptions.hostname)
            if (!dnsAndFamily && rOptions.servername) {
              const dns = dnsConfig.dnsMap.ForSNI
              if (dns) {
                dnsAndFamily = { dns }
                log.info(`域名 ${rOptions.hostname} 在dns中未配置,但使用了 sni: ${rOptions.servername}, 必须使用dns,现默认使用 '${dnsAndFamily.dnsName}' DNS.`)
              } else {
                log.warn(`域名 ${rOptions.hostname} 在dns中未配置,但使用了 sni: ${rOptions.servername},然而DNS服务管理中,并未指定SNI默认使用的DNS。`)
              }
            }
            if (dnsAndFamily) {
              rOptions.lookup = dnsLookup.createLookupFunc(res, dnsAndFamily, 'request url', url, rOptions.port, isDnsIntercept)
              if (dnsAndFamily.family === 6) {
                rOptions.family = 6
              }
              log.debug(`域名 ${rOptions.hostname} DNS: ${dnsAndFamily.dns.dnsName}, family: ${rOptions.family || 4}`)
              res.setHeader('DS-DNS', dnsAndFamily.dns.dnsName === '预设IP' ? 'PreSet' : dnsAndFamily.dns.dnsName.replace(/[^\x20-\x7E]/g, ''))
            } else {
              log.info(`域名 ${rOptions.hostname} 在DNS中未配置`)
            }
          } else {
            log.info(`域名 ${rOptions.hostname} DNS配置不存在`)
          }

          // rOptions.sigalgs = 'RSA-PSS+SHA256:RSA-PSS+SHA512:ECDSA+SHA256'
          // rOptions.agent.options.sigalgs = rOptions.sigalgs

View on GitHub (pinned to 7710cd56cc)

Solutions

  1. Add the ForSNI default DNS to dnsMap in config, e.g. dnsMap.ForSNI = { dnsType: 'ip', dnsName: '...'} per default config (src/config).
  2. Restore the default config entry: merge your personal config diff with the shipped defaults instead of replacing dnsMap wholesale.
  3. Ignore if system DNS is acceptable — the request still proceeds using Node's default lookup; this is a warning, not a failure.

Example fix

// before (config dnsMap)
"dnsMap": { "github.com": { "...": "..." } }
// after
"dnsMap": { "ForSNI": { "dnsType": "https", "dnsName": "doh.pub" }, "github.com": { "...": "..." } }
Defensive patterns

Strategy: validation

Validate before calling

if (!dnsMap?.ForSNI) console.warn('dnsMap.ForSNI missing: SNI domains without explicit mapping will use system DNS')

Type guard

const hasForSNI = (cfg) => cfg && cfg.dnsMap && typeof cfg.dnsMap.ForSNI === 'object' && cfg.dnsMap.ForSNI !== null

Prevention

When it happens

Trigger: HTTPS request to a domain not present in dnsMap, with rOptions.servername set (SNI), while dnsMap contains no `ForSNI` entry — encountered in createRequestHandler's onFree path before building rOptions.lookup.

Common situations: Custom DNS config that lists specific domains but omits the ForSNI default; users editing dnsMap JSON5 by hand and dropping the ForSNI key; configs migrated from older versions where ForSNI did not exist.

Related errors


AI-assisted analysis of docmirror/dev-sidecar@7710cd56cc (2026-08-31). Data as JSON: /api/errors/8ddfd3a3a79a14cb. Report an issue: GitHub.