{"record":{"id":"217372293aae2213","repo":"nodejs/node","slug":"und-err-socks5-addr-type","errorCode":"UND_ERR_SOCKS5_ADDR_TYPE","errorMessage":"Invalid address type in reply: ${addressType}","messagePattern":"Invalid address type in reply: (.+?)","errorType":"exception","errorClass":"Socks5ProxyError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/core/socks5-client.js","lineNumber":343,"sourceCode":"    const addressType = this.buffer[3]\n\n    if (version !== SOCKS_VERSION) {\n      throw new Socks5ProxyError(`Invalid SOCKS version in reply: ${version}`, 'UND_ERR_SOCKS5_REPLY_VERSION')\n    }\n\n    // Calculate the expected response length\n    let responseLength = 4 // VER + REP + RSV + ATYP\n    if (addressType === ADDRESS_TYPES.IPV4) {\n      responseLength += 4 + 2 // IPv4 + port\n    } else if (addressType === ADDRESS_TYPES.DOMAIN) {\n      if (this.buffer.length < 5) {\n        return // Need domain length byte\n      }\n      responseLength += 1 + this.buffer[4] + 2 // length byte + domain + port\n    } else if (addressType === ADDRESS_TYPES.IPV6) {\n      responseLength += 16 + 2 // IPv6 + port\n    } else {\n      throw new Socks5ProxyError(`Invalid address type in reply: ${addressType}`, 'UND_ERR_SOCKS5_ADDR_TYPE')\n    }\n\n    if (this.buffer.length < responseLength) {\n      return // Not enough data for full response\n    }\n\n    if (reply !== REPLY_CODES.SUCCEEDED) {\n      const errorMessage = this.getReplyErrorMessage(reply)\n      throw new Socks5ProxyError(`SOCKS5 connection failed: ${errorMessage}`, `UND_ERR_SOCKS5_REPLY_${reply}`)\n    }\n\n    // Parse bound address and port\n    let boundAddress\n    let offset = 4\n\n    if (addressType === ADDRESS_TYPES.IPV4) {\n      boundAddress = Array.from(this.buffer.subarray(offset, offset + 4)).join('.')\n      offset += 4","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/core/socks5-client.js#L325-L361","documentation":"Thrown in handleConnectResponse() when the ATYP (address type) byte of the CONNECT reply is not IPV4 (0x01), DOMAIN (0x03), or IPV6 (0x04). The bound-address field in RFC 1928 replies uses only those three ATYP values; anything else is malformed.","triggerScenarios":"Server returns an unknown ATYP; buffer desync shifts the byte being interpreted as ATYP; buggy server using a reserved ATYP value.","commonSituations":"Desync from an incompletely consumed prior reply; a proxy that prepends extra header bytes; protocol parser bug.","solutions":["Confirm the full CONNECT reply header (VER+REP+RSV+ATYP) is being read at the correct offset.","Reconnect on a fresh socket to eliminate desync.","Log the raw ATYP byte and surrounding bytes to detect framing issues.","Test against a known-good SOCKS5 server."],"exampleFix":"// diagnosing: log raw bytes\n// debug('connect reply head', this.buffer.subarray(0, 8))\n// then reconnect on a fresh socket if desync is confirmed","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { /* wait for connect response */ } catch (e) {\n  if (e.code === 'UND_ERR_SOCKS5_ADDR_TYPE') {\n    // unexpected ATYP; verify framing or switch proxy\n  } else throw e\n}","preventionTips":["Validate buffer framing before parsing the bound address.","Log raw reply bytes when ATYP is unexpected.","Test against a reference SOCKS5 server."],"tags":["socks5","proxy","protocol","validation","network"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}