From 701aa99a30eb4e43aca3d6bdb80a82ccdb88e4a2 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Thu, 22 Jun 2017 13:18:39 -0600 Subject: [PATCH] added protection against unwanted writes to websocket --- wstunneld.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wstunneld.js b/wstunneld.js index d4a1ca2..0ecf518 100644 --- a/wstunneld.js +++ b/wstunneld.js @@ -96,6 +96,7 @@ module.exports.create = function (copts) { return; } + remote.closing[cid] = true; PromiseA.resolve() .then(function () { remote.clients[cid].end(); @@ -117,6 +118,9 @@ module.exports.create = function (copts) { .catch(function (err) { console.warn('failed to close browser connection', cid, err); }) + .then(function () { + delete remote.closing[cid]; + }) ; } @@ -155,6 +159,7 @@ module.exports.create = function (copts) { token.deviceId = (token.device && (token.device.id || token.device.hostname)) || token.domains.join(','); token.ws = ws; token.clients = {}; + token.closing = {}; token.domains.forEach(function (domainname) { console.log('domainname', domainname); @@ -366,7 +371,7 @@ module.exports.create = function (copts) { console.log('[pipeWs] browser is', cid, 'home-cloud is', packer.socketToId(remote.ws.upgradeReq.socket)); function sendWs(data, serviceOverride) { - if (remote.ws) { + if (remote.ws && !remote.closing[cid]) { try { remote.ws.send(packer.pack(browserAddr, data, serviceOverride), { binary: true }); } catch (err) {