From a10f23a7f19daec6663e75bd36710118f21679ee Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 2 Jun 2026 15:17:16 -0700 Subject: [PATCH] fix(socks): handle IPv4-mapped IPv6 addresses in ipToSocksAddress On dual-stack systems Node.js returns IPv4-mapped IPv6 addresses (e.g. "::ffff:10.0.0.1") from socket.localAddress. These fail net.isIPv4() and fell into the IPv6 branch, producing a malformed SOCKS address. Unwrap the ::ffff: prefix to a plain IPv4 dotted-quad before the isIPv4 check. Fixes: https://github.com/microsoft/playwright/issues/41107 --- packages/utils/socksProxy.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/utils/socksProxy.ts b/packages/utils/socksProxy.ts index 03ca66e618f49..db629b4a12989 100644 --- a/packages/utils/socksProxy.ts +++ b/packages/utils/socksProxy.ts @@ -294,6 +294,11 @@ function hexToNumber(hex: string): number { } function ipToSocksAddress(address: string): number[] { + // Node.js may return IPv4-mapped IPv6 addresses (e.g. "::ffff:10.0.0.1") from + // socket.localAddress on dual-stack systems. Unwrap them to plain IPv4. + const ipv4Mapped = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/i.exec(address); + if (ipv4Mapped) + address = ipv4Mapped[1]; if (net.isIPv4(address)) { return [ 0x01, // IPv4