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

fix([triage-gemini-out-of-scope-findings]): apply four validated findings from gemini repo-review

[._.]/ Adam Eivyf8cb1df5857a
diff --git a/server/lib/commandSecurity.js b/server/lib/commandSecurity.js
index c42a786951..f9a8d32b60 100644
--- a/server/lib/commandSecurity.js
+++ b/server/lib/commandSecurity.js
@@ -23,7 +23,7 @@ export const DANGEROUS_SHELL_CHARS = /[;|&`$(){}[\]<>\\!#*?~]/;
* Parse command string into args, respecting quoted strings.
* e.g. 'git commit -m "msg with spaces"' → ['git', 'commit', '-m', 'msg with spaces']
*/
-function parseCommandArgs(str) {
+export function parseCommandArgs(str) {
const args = [];
let current = '';
let inQuote = null;
diff --git a/server/lib/commandSecurity.test.js b/server/lib/commandSecurity.test.js
index 8ddcd8c6ec..487d040f16 100644
--- a/server/lib/commandSecurity.test.js
+++ b/server/lib/commandSecurity.test.js
@@ -4,7 +4,8 @@ import {
ALLOWED_COMMANDS_SORTED,
DANGEROUS_SHELL_CHARS,
validateCommand,
- redactOutput
+ redactOutput,
+ parseCommandArgs
} from './commandSecurity.js'
describe('commandSecurity', () => {
@@ -198,4 +199,24 @@ describe('commandSecurity', () => {
expect(result).toContain('"name": "app"')
})
})
+
+ describe('parseCommandArgs', () => {
+ it('splits on whitespace when there are no quotes', () => {
+ expect(parseCommandArgs('npm run dev')).toEqual(['npm', 'run', 'dev'])
+ })
+
+ it('keeps double-quoted segments intact', () => {
+ expect(parseCommandArgs('node --opt "arg with spaces"'))
+ .toEqual(['node', '--opt', 'arg with spaces'])
+ })
+
+ it('keeps single-quoted segments intact', () => {
+ expect(parseCommandArgs("git commit -m 'msg with spaces'"))
+ .toEqual(['git', 'commit', '-m', 'msg with spaces'])
+ })
+
+ it('preserves an empty quoted argument', () => {
+ expect(parseCommandArgs('echo ""')).toEqual(['echo', ''])
+ })
+ })
})
diff --git a/server/lib/httpClient.js b/server/lib/httpClient.js
index 914beadb4d..6c2631fde5 100644
--- a/server/lib/httpClient.js
+++ b/server/lib/httpClient.js
@@ -90,7 +90,9 @@ export function insecureFetch(agent) {
has: n => Object.prototype.hasOwnProperty.call(res.headers, n.toLowerCase()),
},
text: () => Promise.resolve(buffer.toString('utf-8')),
- json: () => Promise.resolve(JSON.parse(buffer.toString('utf-8'))),
+ // Defer JSON.parse so a malformed body becomes a promise rejection
+ // (matching Fetch) rather than a synchronous throw from `res.json()`.
+ json: async () => JSON.parse(buffer.toString('utf-8')),
// ArrayBuffer view matching Fetch's Response so call sites can
// `Buffer.from(await res.arrayBuffer())` without branching on
// transport.
diff --git a/server/routes/apps.js b/server/routes/apps.js
index e99d1b0050..2b0911ffce 100644
--- a/server/routes/apps.js
+++ b/server/routes/apps.js
@@ -19,6 +19,7 @@ import { parseEcosystemFromPath, usesPm2 } from '../services/streamingDetect.js'
import { detectAppIcon, getIconContentType, isUsableSvg } from '../services/appIconDetect.js';
import { hasDeployScript } from '../services/appDeployer.js';
import { checkScripts, installScripts, XCODE_SCRIPT_NAMES } from '../services/xcodeScripts.js';
+import { SELF_IMPROVEMENT_TASK_TYPES } from '../services/taskSchedule.js';
import { certPaths } from '../../lib/certPaths.js';
const router = Router();
@@ -404,6 +405,9 @@ router.put('/bulk-task-type/:taskType', asyncHandler(async (req, res) => {
if (typeof enabled !== 'boolean') {
throw new ServerError('enabled (boolean) is required', { status: 400, code: 'VALIDATION_ERROR' });
}
+ if (!SELF_IMPROVEMENT_TASK_TYPES.includes(req.params.taskType)) {
+ throw new ServerError(`Unknown task type '${req.params.taskType}'`, { status: 400, code: 'INVALID_TASK_TYPE' });
+ }
const result = await appsService.bulkUpdateAppTaskTypeOverride(req.params.taskType, { enabled });
console.log(`📋 Bulk ${enabled ? 'enabled' : 'disabled'} task type ${req.params.taskType} for ${result.count} apps`);
@@ -477,6 +481,9 @@ router.put('/:id/task-types/all', loadApp, asyncHandler(async (req, res) => {
// PUT /api/apps/:id/task-types/:taskType - Update a task type override for an app
router.put('/:id/task-types/:taskType', asyncHandler(async (req, res) => {
const { enabled, interval, taskMetadata } = req.body;
+ if (!SELF_IMPROVEMENT_TASK_TYPES.includes(req.params.taskType)) {
+ throw new ServerError(`Unknown task type '${req.params.taskType}'`, { status: 400, code: 'INVALID_TASK_TYPE' });
+ }
if (enabled !== undefined && typeof enabled !== 'boolean') {
throw new ServerError('enabled must be a boolean', { status: 400, code: 'VALIDATION_ERROR' });
}
@@ -884,12 +891,16 @@ router.post('/:id/open-editor', loadApp, asyncHandler(async (req, res) => {
}
}
- // Spawn the editor process detached so it doesn't block
+ // Spawn the editor process detached so it doesn't block.
+ // On Windows, editor binaries are typically `.cmd`/`.bat` shims (e.g. `code.cmd`,
+ // `cursor.cmd`) which Node refuses to spawn without a shell since 20.12.2 — so we
+ // opt into the shell on win32. Args are pre-sanitized for shell metacharacters
+ // above, and the command is allowlisted.
const child = spawn(cmd, args, {
cwd: app.repoPath,
detached: true,
stdio: 'ignore',
- shell: false, // Security: Ensure no shell interpretation
+ shell: process.platform === 'win32',
windowsHide: true
});
child.unref();
@@ -905,11 +916,13 @@ router.post('/:id/open-claude', loadApp, asyncHandler(async (req, res) => {
throw new ServerError('App path does not exist', { status: 400, code: 'PATH_NOT_FOUND' });
}
+ // shell:true on Windows so `claude.cmd` resolves (see open-editor above for the
+ // Node 20.12.2 rationale). No user args reach the command line here.
const child = spawn('claude', [], {
cwd: app.repoPath,
detached: true,
stdio: 'ignore',
- shell: false,
+ shell: process.platform === 'win32',
windowsHide: true
});
child.unref();
diff --git a/server/routes/apps.test.js b/server/routes/apps.test.js
index bb5dd58eae..c310bd9027 100644
--- a/server/routes/apps.test.js
+++ b/server/routes/apps.test.js
@@ -584,6 +584,26 @@ describe('Apps Routes', () => {
expect(response.status).toBe(400);
});
+
+ it('should reject an unknown taskType in the URL', async () => {
+ const response = await request(app)
+ .put('/api/apps/app-001/task-types/not-a-real-task-type')
+ .send({ enabled: true });
+
+ expect(response.status).toBe(400);
+ expect(response.body.code).toBe('INVALID_TASK_TYPE');
+ });
+ });
+
+ describe('PUT /api/apps/bulk-task-type/:taskType', () => {
+ it('should reject an unknown taskType in the URL', async () => {
+ const response = await request(app)
+ .put('/api/apps/bulk-task-type/not-a-real-task-type')
+ .send({ enabled: true });
+
+ expect(response.status).toBe(400);
+ expect(response.body.code).toBe('INVALID_TASK_TYPE');
+ });
});
describe('GET /api/apps/:id/icon', () => {
diff --git a/server/services/pm2.js b/server/services/pm2.js
index 9a2f73811c..a686b17161 100644
--- a/server/services/pm2.js
+++ b/server/services/pm2.js
@@ -5,6 +5,7 @@ import { writeFile, unlink } from 'fs/promises';
import { join, dirname } from 'path';
import { createRequire } from 'module';
import { extractJSONArray, safeJSONParse } from '../lib/fileUtils.js';
+import { parseCommandArgs } from '../lib/commandSecurity.js';
const IS_WIN = process.platform === 'win32';
@@ -387,14 +388,17 @@ export async function getLogs(name, lines = 100, pm2Home = null) {
* @param {string} command Command to run (e.g., "npm run dev")
*/
export async function startWithCommand(name, cwd, command) {
- const [script, ...args] = command.split(' ');
+ // Parse with quote-awareness so `node --opt "arg with spaces"` survives;
+ // a bare split(' ') would shred quoted segments. PM2 accepts `args` as an
+ // array, which avoids re-joining and re-splitting on the way through.
+ const [script, ...args] = parseCommandArgs(command);
return connectAndRun((pm2) => {
return new Promise((resolve, reject) => {
const opts = {
name,
script,
- args: args.join(' '),
+ args,
cwd,
watch: false,
autorestart: true,