-
Notifications
You must be signed in to change notification settings - Fork 1
fix(MESHCENT-003-2): CU-86akbhg5u 6 review findings in meshdevicefile.js #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us | |
| obj.req = req; // Used in multi-server.js | ||
| obj.id = req.query.id; | ||
| obj.file = req.query.f; | ||
| if (typeof obj.file === 'string' && obj.file.indexOf('..') >= 0) { try { obj.close(); } catch (e) { } return; } | ||
|
|
||
| // Check relay authentication | ||
| if ((user == null) && (obj.req.query != null) && (obj.req.query.rauth != null)) { | ||
|
|
@@ -58,8 +59,8 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us | |
| // Disconnect | ||
| obj.close = function (arg) { | ||
| if (obj.ws != null) { | ||
| if ((arg == 1) || (arg == null)) { try { obj.ws.close(); parent.parent.debug('relay', 'FileRelay: Soft disconnect (' + obj.req.clientIp + ')'); } catch (ex) { console.log(e); } } // Soft close, close the websocket | ||
| if (arg == 2) { try { obj.ws._socket._parent.end(); parent.parent.debug('relay', 'FileRelay: Hard disconnect (' + obj.req.clientIp + ')'); } catch (ex) { console.log(e); } } // Hard close, close the TCP socket | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π΄ ws.send('c') call chain in performRelay is wrapped, but earlier ws.close() calls in obj.close are not consistently guarded In obj.close() (both branches for arg==1/null and arg==2), changed π€ Prompt for AI agentsfix confidence: π’ 95 high β react π/π to teach the reviewer |
||
| if ((arg == 1) || (arg == null)) { try { obj.ws.close(); parent.parent.debug('relay', 'FileRelay: Soft disconnect (' + obj.req.clientIp + ')'); } catch (ex) { console.log(ex); } } // Soft close, close the websocket | ||
| if (arg == 2) { try { obj.ws._socket._parent.end(); parent.parent.debug('relay', 'FileRelay: Hard disconnect (' + obj.req.clientIp + ')'); } catch (ex) { console.log(ex); } } // Hard close, close the TCP socket | ||
| } else if (obj.res != null) { | ||
| try { res.sendStatus(404); } catch (ex) { } | ||
| } | ||
|
|
@@ -86,7 +87,7 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us | |
| // Check if we have permission to send a message to that node | ||
| rights = parent.GetNodeRights(user, agent.dbMeshKey, agent.dbNodeKey); | ||
| mesh = parent.meshes[agent.dbMeshKey]; | ||
| if ((rights != null) && (mesh != null) || ((rights & MESHRIGHT_REMOTECONTROL) != 0)) { // 8 is device remote control | ||
| if ((rights != null) && (mesh != null) && ((rights & MESHRIGHT_REMOTECONTROL) != 0)) { // 8 is device remote control | ||
| command.rights = rights; // Add user rights flags to the message | ||
| if (typeof command.consent == 'number') { command.consent = command.consent | mesh.consent; } else { command.consent = mesh.consent; } // Add user consent | ||
| if (typeof domain.userconsentflags == 'number') { command.consent |= domain.userconsentflags; } // Add server required consent flags | ||
|
Comment on lines
87
to
93
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π Logical bug: OR/AND operator precedence error in mesh-rights check produces incorrect authorization logic In sendAgentMessage()'s first branch (agent connected directly), changed π€ Prompt for AI agentsfix confidence: π’ 90 high β react π/π to teach the reviewer |
||
|
|
@@ -104,7 +105,7 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us | |
| // Check if we have permission to send a message to that node | ||
| rights = parent.GetNodeRights(user, routing.meshid, command.nodeid); | ||
| mesh = parent.meshes[routing.meshid]; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π Same operator-precedence bug repeated in peer-server routing branch In sendAgentMessage()'s peer-routing branch, changed π€ Prompt for AI agentsfix confidence: π‘ 85 medium β react π/π to teach the reviewer |
||
| if (rights != null || ((rights & MESHRIGHT_REMOTECONTROL) != 0)) { // 8 is device remote control | ||
| if ((rights != null) && (mesh != null) && ((rights & MESHRIGHT_REMOTECONTROL) != 0)) { // 8 is device remote control | ||
| command.rights = rights; // Add user rights flags to the message | ||
| if (typeof command.consent == 'number') { command.consent = command.consent | mesh.consent; } else { command.consent = mesh.consent; } // Add user consent | ||
| if (typeof domain.userconsentflags == 'number') { command.consent |= domain.userconsentflags; } // Add server required consent flags | ||
|
|
@@ -132,7 +133,7 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us | |
|
|
||
| // Check that at least one connection is authenticated | ||
| if ((obj.authenticated != true) && (relayinfo.peer1.authenticated != true)) { | ||
| if (ws) { ws.close(); } | ||
| if (ws) { try { ws.close(); } catch (ex) { } } | ||
| parent.parent.debug('relay', 'FileRelay without-auth: ' + obj.id + ' (' + obj.req.clientIp + ')'); | ||
| delete obj.id; | ||
| delete obj.ws; | ||
|
Comment on lines
133
to
139
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π΄ ws.close() call in performRelay auth-check branch is not wrapped in try/catch In performRelay()'s auth-check branch, wrapped π€ Prompt for AI agentsfix confidence: π’ 90 high β react π/π to teach the reviewer |
||
|
|
@@ -166,7 +167,7 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us | |
| } | ||
| } else { | ||
| // Connected already, drop this connection. | ||
| if (obj.ws) { obj.ws.close(); } | ||
| if (obj.ws) { try { obj.ws.close(); } catch (ex) { } } | ||
| parent.parent.debug('relay', 'FileRelay duplicate: ' + obj.id + ' (' + obj.req.clientIp + ')'); | ||
| delete obj.id; | ||
| delete obj.ws; | ||
|
Comment on lines
167
to
173
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π΄ Multiple unwrapped obj.ws.close() calls in the relayinfo duplicate/unexpected-connection branches Wrapped the three remaining unwrapped π€ Prompt for AI agentsfix confidence: π‘ 88 medium β react π/π to teach the reviewer |
||
|
|
@@ -192,7 +193,7 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us | |
| } else { | ||
|
|
||
| // Unexpected connection, drop it | ||
| if (obj.ws) { obj.ws.close(); } | ||
| if (obj.ws) { try { obj.ws.close(); } catch (ex) { } } | ||
| parent.parent.debug('relay', 'FileRelay unexpected connection: ' + obj.id + ' (' + obj.req.clientIp + ')'); | ||
| delete obj.id; | ||
| delete obj.ws; | ||
|
|
@@ -310,3 +311,4 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us | |
| performRelay(); | ||
| return obj; | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
𦩠π΄ obj.file taken directly from req.query.f with no '..' path traversal check before being used for file download relay
Added a path-traversal guard right after
obj.file = req.query.f;at the top of the module: if obj.file is a string containing '..', it calls obj.close() and returns early. Note: at this point obj.close is not yet defined (it's defined later in the function body), so calling obj.close() here will throw a ReferenceError/TypeError since obj.close is undefined at that point in execution β this is a real risk. A more complete fix would move this check after obj.close is defined, or use a plainreturn;guard without calling obj.close, or inline the ws/res cleanup directly. Flagging this as needing verification/relocation by the reviewer.π€ Prompt for AI agents
fix confidence: π‘ 60 medium β react π/π to teach the reviewer