{"record":{"id":"8462b655acf594b8","repo":"jstedfast/MailKit","slug":"proxy-server-returned-unknown-address-type","errorCode":null,"errorMessage":"Proxy server returned unknown address type.","messagePattern":"Proxy server returned unknown address type\\.","errorType":"exception","errorClass":"ProxyProtocolException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Proxy/Socks5Client.cs","lineNumber":357,"sourceCode":"\t\tint ProcessPartialConnectResponse (string host, int port, byte[] buffer)\n\t\t{\n\t\t\tVerifySocksVersion (buffer[0]);\n\n\t\t\tif (buffer[1] != (byte) Socks5Reply.Success)\n\t\t\t\tthrow new ProxyProtocolException (string.Format (CultureInfo.InvariantCulture, \"Failed to connect to {0}:{1}: {2}\", host, port, GetFailureReason (buffer[1])));\n\n\t\t\t// +-----+-----+-------+------+----------+----------+\n\t\t\t// | VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |\n\t\t\t// +-----+-----+-------+------+----------+----------+\n\t\t\t// |  1  |  1  | X'00' |  1   | Variable |    2     |\n\t\t\t// +-----+-----+-------+------+----------+----------+\n\t\t\tvar addrType = (Socks5AddressType) buffer[3];\n\n\t\t\tswitch (addrType) {\n\t\t\tcase Socks5AddressType.Domain: return 4 + 1 + buffer[4] + 2;\n\t\t\tcase Socks5AddressType.IPv6: return 4 + 16 + 2;\n\t\t\tcase Socks5AddressType.IPv4: return 4 + 4 + 2;\n\t\t\tdefault: throw new ProxyProtocolException (\"Proxy server returned unknown address type.\");\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Connect to the target host.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Connects to the target host and port through the proxy server.\n\t\t/// </remarks>\n\t\t/// <returns>The connected network stream.</returns>\n\t\t/// <param name=\"host\">The host name of the target server.</param>\n\t\t/// <param name=\"port\">The target server port.</param>\n\t\t/// <param name=\"cancellationToken\">The cancellation token.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"host\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ArgumentOutOfRangeException\">\n\t\t/// <paramref name=\"port\"/> is not between <c>0</c> and <c>65535</c>.","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Proxy/Socks5Client.cs#L339-L375","documentation":"The final CONNECT reply includes BND.ADDR whose type byte (ATYP) must be 1 (IPv4), 3 (domain), or 4 (IPv6). If ProcessPartialConnectResponse sees any other value the response is malformed per RFC 1928, and a ProxyProtocolException is thrown rather than misparsing the remaining bytes.","triggerScenarios":"Socks5Client.Connect/ConnectAsync receiving a corrupt or non-conformant CONNECT reply from the proxy — buggy/rogue proxy software, response stream desynchronized, or a non-SOCKS5 device answering.","commonSituations":"Intercepting middleboxes or broken proxy firmware, reading a response from the wrong server (TLS/plain mixup), or a proxy with a known protocol-implementation bug.","solutions":["Verify the endpoint is a compliant SOCKS5 server (test with curl --socks5) and upgrade/replace buggy proxy software","Ensure the socket stream is not shared/desynchronized (no prior reads from the stream by other code)","Capture the raw reply bytes for the proxy vendor; apply vendor patches or use a different SOCKS5 implementation"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    await socks5.ConnectAsync(proxyHost, proxyPort, target, targetPort);\n} catch (ProxyProtocolException ex) when (ex.Message.Contains(\"unknown address type\")) {\n    log.Error(\"Malformed SOCKS5 reply from {0}:{1} — proxy not RFC 1928 compliant\", proxyHost, proxyPort);\n    // escalate to proxy vendor / fail over to backup proxy\n}","preventionTips":["Use maintained SOCKS5 proxy software and keep it patched","Never share the proxy stream with other readers/writers","Fail over to an alternate proxy on protocol violations"],"tags":["socks5","protocol","proxy"],"backgroundTag":"unexpected-response-shape","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}