{"record":{"id":"8ddfd3a3a79a14cb","repo":"docmirror/dev-sidecar","slug":"roptions-hostname-dns-sni-ropti","errorCode":null,"errorMessage":"域名 ${rOptions.hostname} 在dns中未配置，但使用了 sni: ${rOptions.servername}，然而DNS服务管理中，并未指定SNI默认使用的DNS。","messagePattern":"域名 (.+?) 在dns中未配置，但使用了 sni: (.+?)，然而DNS服务管理中，并未指定SNI默认使用的DNS。","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js","lineNumber":126,"sourceCode":"          }\n        }\n        onFree()\n\n        function onFree () {\n          url = `${rOptions.method} ➜ ${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}`\n          const start = Date.now()\n          log.info('发起代理请求:', url, (rOptions.servername ? `, sni: ${rOptions.servername}` : ''), ', headers:', jsonApi.stringify2(rOptions.headers))\n\n          const isDnsIntercept = {}\n          if (dnsConfig && dnsConfig.dnsMap) {\n            let dnsAndFamily = DnsUtil.getDNSAndFamily(dnsConfig, rOptions.hostname)\n            if (!dnsAndFamily && rOptions.servername) {\n              const dns = dnsConfig.dnsMap.ForSNI\n              if (dns) {\n                dnsAndFamily = { dns }\n                log.info(`域名 ${rOptions.hostname} 在dns中未配置，但使用了 sni: ${rOptions.servername}, 必须使用dns，现默认使用 '${dnsAndFamily.dnsName}' DNS.`)\n              } else {\n                log.warn(`域名 ${rOptions.hostname} 在dns中未配置，但使用了 sni: ${rOptions.servername}，然而DNS服务管理中，并未指定SNI默认使用的DNS。`)\n              }\n            }\n            if (dnsAndFamily) {\n              rOptions.lookup = dnsLookup.createLookupFunc(res, dnsAndFamily, 'request url', url, rOptions.port, isDnsIntercept)\n              if (dnsAndFamily.family === 6) {\n                rOptions.family = 6\n              }\n              log.debug(`域名 ${rOptions.hostname} DNS: ${dnsAndFamily.dns.dnsName}, family: ${rOptions.family || 4}`)\n              res.setHeader('DS-DNS', dnsAndFamily.dns.dnsName === '预设IP' ? 'PreSet' : dnsAndFamily.dns.dnsName.replace(/[^\\x20-\\x7E]/g, ''))\n            } else {\n              log.info(`域名 ${rOptions.hostname} 在DNS中未配置`)\n            }\n          } else {\n            log.info(`域名 ${rOptions.hostname} DNS配置不存在`)\n          }\n\n          // rOptions.sigalgs = 'RSA-PSS+SHA256:RSA-PSS+SHA512:ECDSA+SHA256'\n          // rOptions.agent.options.sigalgs = rOptions.sigalgs","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/docmirror/dev-sidecar/blob/7710cd56cce760c708f30b01d2d4056eb8c402d5/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js#L108-L144","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add the ForSNI default DNS to dnsMap in config, e.g. dnsMap.ForSNI = { dnsType: 'ip', dnsName: '...'} per default config (src/config).","Restore the default config entry: merge your personal config diff with the shipped defaults instead of replacing dnsMap wholesale.","Ignore if system DNS is acceptable — the request still proceeds using Node's default lookup; this is a warning, not a failure."],"exampleFix":"// before (config dnsMap)\n\"dnsMap\": { \"github.com\": { \"...\": \"...\" } }\n// after\n\"dnsMap\": { \"ForSNI\": { \"dnsType\": \"https\", \"dnsName\": \"doh.pub\" }, \"github.com\": { \"...\": \"...\" } }","handlingStrategy":"validation","validationCode":"if (!dnsMap?.ForSNI) console.warn('dnsMap.ForSNI missing: SNI domains without explicit mapping will use system DNS')","typeGuard":"const hasForSNI = (cfg) => cfg && cfg.dnsMap && typeof cfg.dnsMap.ForSNI === 'object' && cfg.dnsMap.ForSNI !== null","tryCatchPattern":null,"preventionTips":["Never replace dnsMap wholesale; extend the shipped default config","Always keep the ForSNI entry when customizing DNS","Diff your user config against defaults after upgrades"],"tags":["dns","sni","config","mitm","proxy"],"backgroundTag":"missing-dns-config","analyzedSha":"7710cd56cce760c708f30b01d2d4056eb8c402d5","analyzedAt":"2026-08-31T22:07:07.234Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}