Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(socks): handle IPv4-mapped IPv6 addresses in ipToSocksAddress (#41110)

Yury Semikhatskydfee7ac309fe
diff --git a/packages/utils/socksProxy.ts b/packages/utils/socksProxy.ts
index 03ca66e618..db629b4a12 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