Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review: tighten SHELL_UNSAFE_RE, needsShell guard, windowsHide on taskkill, fix close/error double-settle

[._.]/ Adam Eivy3816ff29971c
diff --git a/server/routes/apps.js b/server/routes/apps.js
index 6d57d572b6..77495ad12b 100644
--- a/server/routes/apps.js
+++ b/server/routes/apps.js
@@ -644,7 +644,7 @@ router.post('/:id/build', loadApp, asyncHandler(async (req, res) => {
throw new ServerError(`Build command '${cmd}' is not allowed. Allowed: ${[...ALLOWED_BUILD_CMDS].join(', ')}`, { status: 400, code: 'INVALID_BUILD_COMMAND' });
}
- if (WIN_CMD_SHIMS.has(cmd) && args.some(a => SHELL_UNSAFE_RE.test(a))) {
+ if (needsShell(cmd) && args.some(a => SHELL_UNSAFE_RE.test(a))) {
throw new ServerError('Build command args contain shell-unsafe characters', { status: 400, code: 'INVALID_BUILD_COMMAND' });
}
@@ -782,15 +782,14 @@ const IS_WIN32 = process.platform === 'win32';
// native binaries (xcodebuild, swift, make, cargo).
const WIN_CMD_SHIMS = new Set(['npm', 'npx']);
const needsShell = (cmd) => IS_WIN32 && WIN_CMD_SHIMS.has(cmd);
-// Characters cmd.exe interprets as metacharacters when shell:true is active.
-// Validate args for any command that uses a shell shim (npm/npx) so malicious
-// buildCommand strings like "npm run build&whoami" are rejected at parse time.
-const SHELL_UNSAFE_RE = /[&|<>;`$\\^%!]/;
+// Actual cmd.exe metacharacters (& | < > ^ % ! and grouping parens).
+// Validated only when shell is active (needsShell guard at call site).
+const SHELL_UNSAFE_RE = /[&|<>^%!()]/;
// On Windows, SIGTERM kills cmd.exe but orphans its child (npm). Use taskkill
// /T /F to terminate the whole process tree.
const killProc = (child) => {
if (IS_WIN32 && child.pid) {
- spawn('taskkill', ['/T', '/F', '/PID', String(child.pid)], { stdio: 'ignore' }).unref();
+ spawn('taskkill', ['/T', '/F', '/PID', String(child.pid)], { stdio: 'ignore', windowsHide: true }).unref();
} else {
child.kill('SIGTERM');
}
diff --git a/server/services/appUpdater.js b/server/services/appUpdater.js
index 95df4c9017..4d07e1d5f9 100644
--- a/server/services/appUpdater.js
+++ b/server/services/appUpdater.js
@@ -19,7 +19,7 @@ function runCommand(cmd, args, cwd) {
if (!settled) {
settled = true;
if (IS_WIN32 && child.pid) {
- spawn('taskkill', ['/T', '/F', '/PID', String(child.pid)], { stdio: 'ignore' }).unref();
+ spawn('taskkill', ['/T', '/F', '/PID', String(child.pid)], { stdio: 'ignore', windowsHide: true }).unref();
} else {
child.kill('SIGTERM');
}
@@ -29,11 +29,14 @@ function runCommand(cmd, args, cwd) {
child.stdout.on('data', d => { stdout += d; if (stdout.length > MAX_OUTPUT_BYTES) stdout = stdout.slice(-MAX_OUTPUT_BYTES); });
child.stderr.on('data', d => { stderr += d; if (stderr.length > MAX_OUTPUT_BYTES) stderr = stderr.slice(-MAX_OUTPUT_BYTES); });
child.on('close', code => {
- if (!settled) { settled = true; clearTimeout(timer); }
- if (code !== 0) reject(new Error(stderr.trim() || `${cmd} exited with code ${code}`));
- else resolve({ stdout, stderr });
+ if (!settled) {
+ settled = true;
+ clearTimeout(timer);
+ if (code !== 0) reject(new Error(stderr.trim() || `${cmd} exited with code ${code}`));
+ else resolve({ stdout, stderr });
+ }
});
- child.on('error', err => { if (!settled) { settled = true; clearTimeout(timer); } reject(err); });
+ child.on('error', err => { if (!settled) { settled = true; clearTimeout(timer); reject(err); } });
});
}