unEscape ssh/rdp creds from db (#6001)

Signed-off-by: si458 <simonsmith5521@gmail.com>

Simon Smith committed Apr 9, 2024 at 11:47 UTC 4ba08a96f7419401e4f769bf08d0bce6a809fe3c
2 files changed +7 -3
apprelays.js
+6 -3
@@ -983,6 +983,7 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
983 if ((node == null) || (visible == false) || ((rights & MESHRIGHT_REMOTECONTROL) == 0)) { obj.close(); return; }
984 if ((rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_REMOTEVIEWONLY) != 0)) { obj.viewonly = true; }
985 if ((rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_DESKLIMITEDINPUT) != 0)) { obj.limitedinput = true; }
986 + node = parent.common.unEscapeLinksFieldName(node); // unEscape node data for rdp/ssh credentials
987 obj.mtype = node.mtype; // Store the device group type
988 obj.meshid = node.meshid; // Store the MeshID
989
@@ -1315,7 +1316,7 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
1316 // Check if we have SSH credentials for this device
1317 parent.parent.db.Get(obj.cookie.nodeid, function (err, nodes) {
1318 if ((err != null) || (nodes == null) || (nodes.length != 1)) return;
1318 - const node = nodes[0];
1319 + const node = parent.common.unEscapeLinksFieldName(nodes[0]); // unEscape node data for rdp/ssh credentials
1320 if ((domain.allowsavingdevicecredentials === false) || (node.ssh == null) || (typeof node.ssh != 'object') || (node.ssh[obj.userid] == null) || (typeof node.ssh[obj.userid].u != 'string') || ((typeof node.ssh[obj.userid].p != 'string') && (typeof node.ssh[obj.userid].k != 'string'))) {
1321 // Send a request for SSH authentication
1322 try { ws.send(JSON.stringify({ action: 'sshauth' })) } catch (ex) { }
@@ -1363,7 +1364,7 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
1364 obj.termSize = msg;
1365 parent.parent.db.Get(obj.cookie.nodeid, function (err, nodes) {
1366 if ((err != null) || (nodes == null) || (nodes.length != 1)) return;
1366 - const node = nodes[0];
1367 + const node = parent.common.unEscapeLinksFieldName(nodes[0]); // unEscape node data for rdp/ssh credentials
1368 if (node.ssh != null) {
1369 obj.username = node.ssh.u;
1370 obj.privateKey = node.ssh.k;
@@ -1405,7 +1406,7 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
1406 parent.parent.db.Get(obj.cookie.nodeid, function (err, nodes) {
1407 if (obj.cookie == null) return; // obj has been cleaned up, just exit.
1408 if ((err != null) || (nodes == null) || (nodes.length != 1)) { parent.parent.debug('relay', 'SSH: Invalid device'); obj.close(); }
1408 - const node = nodes[0];
1409 + const node = parent.common.unEscapeLinksFieldName(nodes[0]); // unEscape node data for rdp/ssh credentials
1410 obj.nodeid = node._id; // Store the NodeID
1411 obj.meshid = node.meshid; // Store the MeshID
1412 obj.mtype = node.mtype; // Store the device group type
@@ -1738,6 +1739,7 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u
1739 if ((user == null) || (req.query.nodeid == null)) { obj.close(); return; } // Invalid nodeid
1740 parent.GetNodeWithRights(domain, user, req.query.nodeid, function (node, rights, visible) {
1741 if (obj.ws == null) return; // obj has been cleaned up, just exit.
1742 + node = parent.common.unEscapeLinksFieldName(node); // unEscape node data for rdp/ssh credentials
1743
1744 // Check permissions
1745 if ((rights & 8) == 0) { obj.close(); return; } // No MESHRIGHT_REMOTECONTROL rights
@@ -2267,6 +2269,7 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
2269 if ((user == null) || (req.query.nodeid == null)) { obj.close(); return; } // Invalid nodeid
2270 parent.GetNodeWithRights(domain, user, req.query.nodeid, function (node, rights, visible) {
2271 if (obj.ws == null) return; // obj has been cleaned up, just exit.
2272 + node = parent.common.unEscapeLinksFieldName(node); // unEscape node data for rdp/ssh credentials
2273
2274 // Check permissions
2275 if ((rights & 8) == 0) { obj.close(); return; } // No MESHRIGHT_REMOTECONTROL rights
meshuser.js
+1
@@ -3226,6 +3226,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3226 if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'changedevice', responseid: command.responseid, result: 'Access Denied' })); } catch (ex) { } }
3227 return;
3228 }
3229 + node = common.unEscapeLinksFieldName(node); // unEscape node data for rdp/ssh credentials
3230 var mesh = parent.meshes[node.meshid], amtchange = 0;
3231
3232 // Ready the node change event