From 59d591bce6feebe60642782d890854e04131ddc9 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 26 May 2021 16:51:38 +0200 Subject: [PATCH] chore(port-forwarding): validate forwarded ports on the client side (#6756) --- src/browserServerImpl.ts | 2 +- src/client/browserType.ts | 1 + src/client/playwright.ts | 1 + src/client/socksSocket.ts | 9 +++++++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/browserServerImpl.ts b/src/browserServerImpl.ts index 7793bdb010..a5a9bd8e14 100644 --- a/src/browserServerImpl.ts +++ b/src/browserServerImpl.ts @@ -97,7 +97,7 @@ export class BrowserServerLauncherImpl implements BrowserServerLauncher { portForwardingServer.enablePortForwarding(ports); }); const incomingSocksSocketHandler = (socket: SocksInterceptedSocketHandler) => { - playwrightDispatcher._dispatchEvent('incomingSocksSocket', { socket: new SocksSocketDispatcher(playwrightDispatcher._scope, socket) }); + playwrightDispatcher._dispatchEvent('incomingSocksSocket', { socket: new SocksSocketDispatcher(playwrightDispatcher, socket) }); }; portForwardingServer.on('incomingSocksSocket', incomingSocksSocketHandler); diff --git a/src/client/browserType.ts b/src/client/browserType.ts index 4d5854cc52..10122efd08 100644 --- a/src/client/browserType.ts +++ b/src/client/browserType.ts @@ -189,6 +189,7 @@ export class BrowserType extends ChannelOwner this._socket.end()); + assert(parent instanceof Playwright); + + assert(parent._forwardPorts.includes(this._initializer.dstPort)); + assert(isLocalIpAddress(this._initializer.dstAddr)); if (isUnderTest() && process.env.PW_TEST_PROXY_TARGET) this._initializer.dstPort = Number(process.env.PW_TEST_PROXY_TARGET); - assert(isLocalIpAddress(this._initializer.dstAddr)); this._socket = net.createConnection(this._initializer.dstPort, this._initializer.dstAddr); this._socket.on('error', (err: Error) => this._channel.error({error: String(err)})); @@ -50,6 +53,8 @@ export class SocksSocket extends ChannelOwner this._socket.end()); + + this._connection.on('disconnect', () => this._socket.end()); } async write(data: Buffer): Promise {