Skip to content

fix(MESHCENT-004-2): 4 review findings across 2 files - #148

Draft
flamingo[bot] wants to merge 2 commits into
masterfrom
ai-fix/meshcent-004-2-dde0af84-6542cba8
Draft

fix(MESHCENT-004-2): 4 review findings across 2 files#148
flamingo[bot] wants to merge 2 commits into
masterfrom
ai-fix/meshcent-004-2-dde0af84-6542cba8

Conversation

@flamingo

@flamingo flamingo Bot commented Aug 24, 2026

Copy link
Copy Markdown

Closes 4 review findings across 2 files.

Draft — this is a starting point, not a finished change. The fix required judgment, so read it before trusting it.

# Fix confidence Finding Location
1 🟡 80 medium mkdir/mkfile commands use raw cmd.path without '..' traversal validation agents/agentrecoverycore.js:271
2 🟡 65 medium File deletion command 'rm' processes user-supplied paths without a '..' traversal check agents/agentrecoverycore.js:280
3 🟢 90 high agentrecoverycore.js is missing jshint header and 'use strict' agents/agentrecoverycore.js:1
4 🟢 90 high meshinstall-initd.sh builds and eval's a command string containing unescaped shell metacharacters via su -c agents/meshinstall-initd.sh:44

What changed — and what was deliberately left — is explained per finding as inline review comments on the lines each finding touched.


Run: https://product-hub.flamingo.so/admin/code-review
Run id: 6542cba8-5031-4f6a-9825-da6bc2c6e58e

Merging this PR is recorded as acceptance of the rule that produced it;
closing it unmerged is recorded as rejection. Both feed rule health, so
closing a wrong suggestion is useful rather than merely tidy.

@flamingo flamingo Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 What this fix changed, finding by finding

4 finding(s) fixed in this draft — 4 explained inline on the diff.

{
if ((cmd.delfiles[i] == null) || (cmd.delfiles[i].indexOf('..') >= 0)) { continue; }
try { deleteFolderRecursive(path.join(cmd.path, cmd.delfiles[i]), cmd.rec); } catch (e) { }
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🔴 mkdir/mkfile commands use raw cmd.path without '..' traversal validation

In the WebSocket file-command handler (protocol 5 switch), added '..' traversal guards to the mkdir case (checks cmd.path before fs.mkdirSync) and the mkfile case (checks cmd.path before fs.openSync/fs.closeSync); both now silently break if cmd.path is null or contains .., matching the established convention referenced in the finding.

🤖 Prompt for AI agents
In agents/agentrecoverycore.js around line 271, review and complete this code-review fix: mkdir/mkfile commands use raw cmd.path without '..' traversal validation.
What the draft fix changed: In the WebSocket file-command handler (protocol 5 switch), added `'..'` traversal guards to the `mkdir` case (checks `cmd.path` before `fs.mkdirSync`) and the `mkfile` case (checks `cmd.path` before `fs.openSync`/`fs.closeSync`); both now silently `break` if `cmd.path` is null or contains `..`, matching the established convention referenced in the finding.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟡 80 medium — react 👍/👎 to teach the reviewer

Comment on lines 258 to 279
break;
case 'mkdir': {
// Create a new empty folder
if ((cmd.path == null) || (cmd.path.indexOf('..') >= 0)) { break; }
fs.mkdirSync(cmd.path);
break;
}
case 'mkfile': {
// Create a new empty file
if ((cmd.path == null) || (cmd.path.indexOf('..') >= 0)) { break; }
fs.closeSync(fs.openSync(cmd.path, 'w'));
break;
}
case 'rm': {
// Delete, possibly recursive delete
if ((cmd.path == null) || (cmd.path.indexOf('..') >= 0)) { break; }
for (var i in cmd.delfiles)
{
if ((cmd.delfiles[i] == null) || (cmd.delfiles[i].indexOf('..') >= 0)) { continue; }
try { deleteFolderRecursive(path.join(cmd.path, cmd.delfiles[i]), cmd.rec); } catch (e) { }
}
break;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🔴 File deletion command 'rm' processes user-supplied paths without a '..' traversal check

In the rm case of the same handler, added a guard rejecting the whole operation if cmd.path contains .., and added a per-entry check inside the for (var i in cmd.delfiles) loop to continue (skip) any cmd.delfiles[i] entry containing .. before it is joined into a path and passed to deleteFolderRecursive. This blocks the described traversal vector; note it does not add symlink or absolute-path canonicalization checks beyond the literal .. substring test, consistent with the same convention used elsewhere in this codebase.

🤖 Prompt for AI agents
In agents/agentrecoverycore.js around line 280, review and complete this code-review fix: File deletion command 'rm' processes user-supplied paths without a '..' traversal check.
What the draft fix changed: In the `rm` case of the same handler, added a guard rejecting the whole operation if `cmd.path` contains `..`, and added a per-entry check inside the `for (var i in cmd.delfiles)` loop to `continue` (skip) any `cmd.delfiles[i]` entry containing `..` before it is joined into a path and passed to `deleteFolderRecursive`. This blocks the described traversal vector; note it does not add symlink or absolute-path canonicalization checks beyond the literal `..` substring test, consistent with the same convention used elsewhere in this codebase.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟡 65 medium — react 👍/👎 to teach the reviewer

@@ -1,4 +1,7 @@

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🟠 agentrecoverycore.js is missing jshint header and 'use strict'

Added the standard header block (/*jshint node: true */, /*jshint strict: false */, "use strict";) at the top of the file, immediately before the existing var http = require('http'); line, matching the convention used in other server-side modules; no other lines were altered.

🤖 Prompt for AI agents
In agents/agentrecoverycore.js around line 1, review and complete this code-review fix: agentrecoverycore.js is missing jshint header and 'use strict'.
What the draft fix changed: Added the standard header block (`/*jshint node: true */`, `/*jshint strict: false */`, `"use strict";`) at the top of the file, immediately before the existing `var http = require('http');` line, matching the convention used in other server-side modules; no other lines were altered.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟢 90 high — react 👍/👎 to teach the reviewer

fi
rm -f $"PIDFILE"
rm -f "$PIDFILE"
fi

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🔴 meshinstall-initd.sh builds and eval's a command string containing unescaped shell metacharacters via su -c

In the stop() function, changed rm -f $"PIDFILE" to rm -f "$PIDFILE", correcting the malformed variable expansion/quoting ($"PIDFILE" treated "PIDFILE" as a literal string with a stray $, rather than expanding the PIDFILE variable) so the correct pidfile path is removed. This directly matches the suggested fix. Note: the broader concern raised about su -c "$CMD" construction and potential injection if SCRIPT/RUNAS/LOGFILE become templated from external input was not restructured, since those variables are currently static literals in this file and no injection path exists today; addressing that fully would require architectural changes (e.g., using su -s /bin/sh -c with an array-based exec or avoiding string interpolation entirely) that are out of scope for a minimal, safe fix and risk breaking the existing JS payload escaping.

🤖 Prompt for AI agents
In agents/meshinstall-initd.sh around line 44, review and complete this code-review fix: meshinstall-initd.sh builds and eval's a command string containing unescaped shell metacharacters via su -c.
What the draft fix changed: In the stop() function, changed `rm -f $"PIDFILE"` to `rm -f "$PIDFILE"`, correcting the malformed variable expansion/quoting (`$"PIDFILE"` treated `"PIDFILE"` as a literal string with a stray `$`, rather than expanding the `PIDFILE` variable) so the correct pidfile path is removed. This directly matches the suggested fix. Note: the broader concern raised about `su -c "$CMD"` construction and potential injection if SCRIPT/RUNAS/LOGFILE become templated from external input was not restructured, since those variables are currently static literals in this file and no injection path exists today; addressing that fully would require architectural changes (e.g., using `su -s /bin/sh -c` with an array-based exec or avoiding string interpolation entirely) that are out of scope for a minimal, safe fix and risk breaking the existing JS payload escaping.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟢 90 high — react 👍/👎 to teach the reviewer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants