From e3e6757e476f0a2109197254dddfd68fef338c76 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 16 Apr 2023 17:13:47 -0400 Subject: [PATCH] * Refactor multiSocket.ts to check for server mode before checking for allowedPorts inclusion when accepting a new socket connection. --- src/proxies/multiSocket.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/proxies/multiSocket.ts b/src/proxies/multiSocket.ts index 0671856..ade8eed 100644 --- a/src/proxies/multiSocket.ts +++ b/src/proxies/multiSocket.ts @@ -204,17 +204,19 @@ export default class MultiSocketProxy extends Proxy { decode: this._server ? json.decode : socketEncoding.decode, }, async onmessage(m: SocketRequest | TcpSocketConnectOpts) { - if ( - self._allowedPorts.length && - !self._allowedPorts.includes((m as TcpSocketConnectOpts).port) - ) { - self.get(await self._getPublicKey(peer)).messages.errorSocket.send({ - id: (m as SocketRequest).id, - err: new Error( - `port ${(m as TcpSocketConnectOpts).port} not allowed` - ), - }); - return; + if (self._server) { + if ( + self._allowedPorts.length && + !self._allowedPorts.includes((m as TcpSocketConnectOpts).port) + ) { + self.get(await self._getPublicKey(peer)).messages.errorSocket.send({ + id: (m as SocketRequest).id, + err: new Error( + `port ${(m as TcpSocketConnectOpts).port} not allowed` + ), + }); + return; + } } m = m as SocketRequest;