Fixed agent tunnel unable to connect.

Ylian Saint-Hilaire committed Jun 17, 2020 at 10:28 UTC 6668f88ed389929e9047001e06b72f551fb7a248
5 files changed +8 -4
agents/MeshCmd-signed.exe
Binary files a/agents/MeshCmd-signed.exe and b/agents/MeshCmd-signed.exe differ
agents/MeshCmd64-signed.exe
Binary files a/agents/MeshCmd64-signed.exe and b/agents/MeshCmd64-signed.exe differ
agents/meshcore.js
+2 -1
@@ -688,6 +688,7 @@ function createMeshCore(agent) {
688 // Create a new tunnel object
689 var xurl = getServerTargetUrlEx(data.value);
690 if (xurl != null) {
691 + xurl = xurl.split('$').join('%24').split('@').join('%40'); // Escape the $ and @ characters
692 var woptions = http.parseUri(xurl);
693 woptions.rejectUnauthorized = 0;
694 //sendConsoleText(JSON.stringify(woptions));
@@ -2892,7 +2893,7 @@ function createMeshCore(agent) {
2893 } else {
2894 var httprequest = null;
2895 try {
2895 - var options = http.parseUri(args['_'][0]);
2896 + var options = http.parseUri(args['_'][0].split('$').join('%24').split('@').join('%40')); // Escape the $ and @ characters in the URL
2897 options.rejectUnauthorized = 0;
2898 httprequest = http.request(options);
2899 } catch (e) { response = 'Invalid HTTP websocket request'; }
meshdesktopmultiplex.js
+2 -2
@@ -93,7 +93,7 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
93
94 // Add an agent or viewer
95 obj.addPeer = function (peer) {
96 - if (obj.viewers == null) return;
96 + if (obj.viewers == null) { parent.parent.debug('relay', 'DesktopRelay: Error, addingPeer on disposed session'); return; }
97 if (peer.req.query.browser) {
98 //console.log('addPeer-viewer', obj.nodeid);
99
@@ -138,7 +138,7 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
138 obj.sendSessionMetadata();
139 } else {
140 //console.log('addPeer-agent', obj.nodeid);
141 - if (obj.agent != null) return false;
141 + if (obj.agent != null) { parent.parent.debug('relay', 'DesktopRelay: Error, duplicate agent connection'); return false; }
142
143 // Setup the agent
144 obj.agent = peer;
webserver.js
+4 -1
@@ -4270,6 +4270,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4270 parent.debug('webrequest', '(' + req.clientIp + ') ' + req.url);
4271 res.removeHeader('X-Powered-By');
4272
4273 + // Skip the rest is this is an agent connection
4274 + if ((req.url.indexOf('/meshrelay.ashx/.websocket') >= 0) || (req.url.indexOf('/agent.ashx/.websocket') >= 0)) { next(); return; }
4275 +
4276 // If this domain has configured headers, use them.
4277 // Example headers: { 'Strict-Transport-Security': 'max-age=360000;includeSubDomains' };
4278 // { 'Referrer-Policy': 'no-referrer', 'x-frame-options': 'SAMEORIGIN', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src http: ws: data: 'self';script-src http: 'unsafe-inline';style-src http: 'unsafe-inline'" };
@@ -4293,7 +4296,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4296 if ((req.session.ip != null) && (req.clientIp != null) && (req.session.ip != req.clientIp)) { req.session = {}; }
4297
4298 // Extend the session time by forcing a change to the session every minute.
4296 - req.session.nowInMinutes = Math.floor(Date.now() / 60e3);
4299 + if (req.session.userid != null) { req.session.nowInMinutes = Math.floor(Date.now() / 60e3); } else { delete req.session.nowInMinutes; }
4300
4301 // Detect if this is a file sharing domain, if so, just share files.
4302 if ((domain != null) && (domain.share != null)) {