{"record":{"id":"1a99073307e9205e","repo":"jstedfast/MailKit","slug":"proxy-server-responded-with-unknown-socks-version-0","errorCode":null,"errorMessage":"Proxy server responded with unknown SOCKS version: {0}","messagePattern":"Proxy server responded with unknown SOCKS version: (.+?)","errorType":"exception","errorClass":"ProxyProtocolException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Proxy/Socks5Client.cs","lineNumber":172,"sourceCode":"\t\t\t}\n\t\t}\n\n\t\tinternal static Socks5AddressType GetAddressType (string host, out IPAddress? ip)\n\t\t{\n\t\t\tif (!IPAddress.TryParse (host, out ip))\n\t\t\t\treturn Socks5AddressType.Domain;\n\n\t\t\tswitch (ip.AddressFamily) {\n\t\t\tcase AddressFamily.InterNetworkV6: return Socks5AddressType.IPv6;\n\t\t\tcase AddressFamily.InterNetwork: return Socks5AddressType.IPv4;\n\t\t\tdefault: throw new ArgumentException (\"The host address must be an IPv4 or IPv6 address.\", nameof (host));\n\t\t\t}\n\t\t}\n\n\t\tvoid VerifySocksVersion (byte version)\n\t\t{\n\t\t\tif (version != (byte) SocksVersion)\n\t\t\t\tthrow new ProxyProtocolException (string.Format (CultureInfo.InvariantCulture, \"Proxy server responded with unknown SOCKS version: {0}\", (int) version));\n\t\t}\n\n\t\tbyte[] GetNegotiateAuthMethodCommand (Socks5AuthMethod[] methods)\n\t\t{\n\t\t\t// +-----+----------+----------+\n\t\t\t// | VER | NMETHODS | METHODS  |\n\t\t\t// +-----+----------+----------+\n\t\t\t// |  1  |    1     | 1 to 255 |\n\t\t\t// +-----+----------+----------+\n\t\t\tvar buffer = new byte[2 + methods.Length];\n\t\t\tint n = 0;\n\n\t\t\tbuffer[n++] = (byte) SocksVersion;\n\t\t\tbuffer[n++] = (byte) methods.Length;\n\t\t\tfor (int i = 0; i < methods.Length; i++)\n\t\t\t\tbuffer[n++] = (byte) methods[i];\n\n\t\t\treturn buffer;","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Proxy/Socks5Client.cs#L154-L190","documentation":"During SOCKS5 handshake the server must echo protocol version 5 in its responses. VerifySocksVersion throws ProxyProtocolException when the version byte differs, meaning the endpoint is not behaving as a SOCKS5 proxy (wrong service, an HTTP proxy, a captive portal, or garbage).","triggerScenarios":"Calling Socks5Client.Connect/ConnectAsync against a server that is not SOCKS5: pointed at an HTTP proxy port, a TLS-wrapped SOCKS endpoint, or a plain web server; also when responses get corrupted mid-stream (ProcessPartialConnectResponse).","commonSituations":"Config mistake mixing up proxy ports (SOCKS5 client pointed at an HTTP CONNECT port 3128/8080), proxy behind TLS requiring SslStream wrapping first, or transparent proxies returning HTML error pages.","solutions":["Confirm the proxy port is actually SOCKS5 (e.g. curl --socks5 host:port) and fix the port in configuration","If the proxy is SOCKS5 over TLS, wrap the connection in SSL before/with the proxy client as documented","Check for interception devices/firewalls rewriting the response; test from an unrestricted network"],"exampleFix":"// before\nproxyClient.ProxyClient = new Socks5Client { ProxyHost = \"proxy\", ProxyPort = 3128 }; // HTTP proxy port\n// after\nproxyClient.ProxyClient = new Socks5Client { ProxyHost = \"proxy\", ProxyPort = 1080 }; // real SOCKS5 port","handlingStrategy":"try-catch","validationCode":"// pre-flight outside the app:\n// printf '\\x05\\x01\\x00' | nc proxy 1080 | xxd  # first byte must be 0x05","typeGuard":null,"tryCatchPattern":"try {\n    await socks5.ConnectAsync(proxyHost, proxyPort, target, targetPort);\n} catch (ProxyProtocolException ex) when (ex.Message.Contains(\"unknown SOCKS version\")) {\n    log.Error(\"Endpoint {0}:{1} is not SOCKS5 — check proxy type/port/TLS\", proxyHost, proxyPort);\n}","preventionTips":["Keep SOCKS5 and HTTP proxy ports distinct in configuration","Remember SOCKS5-over-TLS needs SSL wrapping first","Test proxy type with curl --socks5 during environment provisioning"],"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"}