{"record":{"id":"00494274af3ebaeb","repo":"iOfficeAI/OfficeCLI","slug":"could-not-resolve-host-host","errorCode":null,"errorMessage":"Could not resolve host '{host}'.","messagePattern":"Could not resolve host '(.+?)'\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/SsrfGuard.cs","lineNumber":54,"sourceCode":"    public static SocketsHttpHandler CreateGuardedHandler(string what)\n    {\n        return new SocketsHttpHandler\n        {\n            AllowAutoRedirect = true,\n            MaxAutomaticRedirections = 10,\n            ConnectCallback = async (ctx, ct) =>\n            {\n                var host = ctx.DnsEndPoint.Host;\n                var addresses = await Dns.GetHostAddressesAsync(host, ct).ConfigureAwait(false);\n                foreach (var addr in addresses)\n                {\n                    if (!IsPublicAddress(addr))\n                        throw new ArgumentException(\n                            $\"Refusing to fetch {what} from non-public address '{addr}' (host '{host}'). \" +\n                            $\"Remote {what} sources must resolve to a public IP (SSRF protection).\");\n                }\n                var target = addresses.FirstOrDefault()\n                    ?? throw new ArgumentException($\"Could not resolve host '{host}'.\");\n                var socket = new Socket(SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };\n                try\n                {\n                    await socket.ConnectAsync(target, ctx.DnsEndPoint.Port, ct).ConfigureAwait(false);\n                    return new NetworkStream(socket, ownsSocket: true);\n                }\n                catch\n                {\n                    socket.Dispose();\n                    throw;\n                }\n            }\n        };\n    }\n\n    /// <summary>\n    /// Shared cap on a single remote fetch, to bound memory use on a hostile or\n    /// accidentally-huge response. Without it the default HttpClient buffering","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/SsrfGuard.cs#L36-L72","documentation":"Thrown by the guarded ConnectCallback when DNS returned an empty address list for the host (addresses.FirstOrDefault() is null). It is a fallback: GetHostAddressesAsync usually throws outright on NXDOMAIN, but this guard catches the empty-result case so a no-address host produces a clear message rather than a NullReferenceException downstream.","triggerScenarios":"An image=/file= URL whose hostname does not resolve (typo, non-existent domain), or DNS returned zero A/AAAA records.","commonSituations":"Typo in the hostname; DNS not configured / offline; the host is a short name that only resolves inside a specific network.","solutions":["Verify the hostname with `nslookup` / `dig` from the same machine.","Correct the typo or use the fully-qualified domain name.","Check network connectivity and DNS configuration."],"exampleFix":"// before\npicture = \"https://exmaple.com/x.png\"  // typo: exmaple\n// after\npicture = \"https://example.com/x.png\"","handlingStrategy":"try-catch","validationCode":"async Task<bool> HostResolves(string url)\n{\n    try { return (await System.Net.Dns.GetHostAddressesAsync(new Uri(url).Host)).Length > 0; }\n    catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try { bytes = await client.GetByteArrayAsync(url); }\ncatch (System.ArgumentException ex) when (ex.Message.Contains(\"Could not resolve host\"))\n{ /* hostname has no DNS records; fix the URL */ }\ncatch (System.Net.Sockets.SocketException) { /* NXDOMAIN / network error */ }","preventionTips":["Validate hostnames at input time (well-formed, resolvable).","Provide a clear 'image not reachable' path in your UI/agent for network failures."],"tags":["network","dns","http","fetch"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}