Fix for #2485

Ylian Saint-Hilaire committed Apr 8, 2021 at 10:12 UTC 2ded4c60d5cf7ee29b1eb9e9bdc8588c60b8d82a
1 file changed +12 -14
meshuser.js
+12 -14
@@ -4216,20 +4216,18 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4216 {
4217 // Check if this user has rights on this nodeid
4218 if (common.validateString(command.nodeid, 1, 1024) == false) break; // Check nodeid
4219 - db.Get(command.nodeid, function (err, nodes) { // TODO: Make a NodeRights(user) method that also does not do a db call if agent is connected (???)
4220 - if ((err == null) && (nodes.length == 1)) {
4221 - if ((parent.GetMeshRights(user, nodes[0].meshid) & MESHRIGHT_REMOTECONTROL) != 0) {
4222 - // Add a user authentication cookie to a url
4223 - var cookieContent = { userid: user._id, domainid: user.domain };
4224 - if (command.nodeid) { cookieContent.nodeid = command.nodeid; }
4225 - if (command.tcpaddr) { cookieContent.tcpaddr = command.tcpaddr; } // Indicates the browser want to agent to TCP connect to a remote address
4226 - if (command.tcpport) { cookieContent.tcpport = command.tcpport; } // Indicates the browser want to agent to TCP connect to a remote port
4227 - if (command.ip) { cookieContent.ip = command.ip; } // Indicates the browser want to agent to relay a TCP connection to a IP:port
4228 - command.cookie = parent.parent.encodeCookie(cookieContent, parent.parent.loginCookieEncryptionKey);
4229 - command.trustedCert = parent.isTrustedCert(domain);
4230 - try { ws.send(JSON.stringify(command)); } catch (ex) { }
4231 - }
4232 - }
4219 + parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) {
4220 + if ((node == null) || ((rights & MESHRIGHT_REMOTECONTROL) == 0) || (visible == false)) return; // Access denied.
4221 +
4222 + // Add a user authentication cookie to a url
4223 + var cookieContent = { userid: user._id, domainid: user.domain };
4224 + if (command.nodeid) { cookieContent.nodeid = command.nodeid; }
4225 + if (command.tcpaddr) { cookieContent.tcpaddr = command.tcpaddr; } // Indicates the browser want to agent to TCP connect to a remote address
4226 + if (command.tcpport) { cookieContent.tcpport = command.tcpport; } // Indicates the browser want to agent to TCP connect to a remote port
4227 + if (command.ip) { cookieContent.ip = command.ip; } // Indicates the browser want to agent to relay a TCP connection to a IP:port
4228 + command.cookie = parent.parent.encodeCookie(cookieContent, parent.parent.loginCookieEncryptionKey);
4229 + command.trustedCert = parent.isTrustedCert(domain);
4230 + try { ws.send(JSON.stringify(command)); } catch (ex) { }
4231 });
4232 break;
4233 }