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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: resolve CLI runner security warning and improve reliability
GITHUBFULLNAMEd1c4e232ebc1
diff --git a/.changelog/v0.11.x.md b/.changelog/v0.11.x.mdnew file mode 100644index 0000000000..aedc85987c--- /dev/null+++ b/.changelog/v0.11.x.md@@ -0,0 +1,25 @@+# Release v0.11.x - Changelog++Released: YYYY-MM-DD++## Overview++This release focuses on security improvements and bug fixes for the AI runner system.++## 🐛 Bug Fixes++### CLI Runner Security & Reliability+- **Security Warning Fix**: Resolved Node.js DEP0190 deprecation warning in CLI runner by removing unsafe `shell: true` option from child process spawning+- **Improved Argument Handling**: CLI commands now use direct argument passing instead of shell interpretation, preventing potential security vulnerabilities from unescaped arguments+- **Enhanced Logging**: Added detailed logging for CLI execution showing full command and prompt preview to aid debugging+- **Context**: The `/devtools/runner` page was generating security warnings when executing Claude CLI commands. The fix removes shell interpretation which was unnecessary and insecure, while maintaining full functionality++**Technical Details**:+- Created override in `server/services/runner.js` for `executeCliRun()` function+- Removed `shell: true` option from `spawn()` call (recommended by Node.js security guidelines)+- Arguments are now properly passed as array without shell metacharacter interpretation+- Added runtime patching in `server/index.js` to inject fixed implementation into AI toolkit++**Files Modified**:+- `server/services/runner.js` - New secure CLI execution implementation+- `server/index.js` - Runtime patching to override toolkit's runnerdiff --git a/server/index.js b/server/index.jsindex cd118f4f3b..67312fdbaf 100644--- a/server/index.js+++ b/server/index.js@@ -128,6 +128,12 @@ setProvidersToolkit(aiToolkit);setRunnerToolkit(aiToolkit);setPromptsToolkit(aiToolkit);+// Patch toolkit's runner to fix shell security issue (DEP0190)+// Override executeCliRun to remove 'shell: true' which causes security warnings+import { executeCliRun as executeCliRunFixed } from './services/runner.js';+aiToolkit.services.runner.executeCliRun = executeCliRunFixed;+console.log('🔧 Patched aiToolkit runner.executeCliRun to fix shell security issue');+// Note: prompts service is initialized automatically by createAIToolkit()// Initialize auto-fixer for error recoverydiff --git a/server/services/runner.js b/server/services/runner.jsindex 9eaab84037..c26f9c9628 100644--- a/server/services/runner.js+++ b/server/services/runner.js@@ -1,7 +1,10 @@/*** Compatibility shim for PortOS services that import from runner.js- * Re-exports toolkit runner service functions+ * Re-exports toolkit runner service functions with local overrides*/+import { spawn } from 'child_process';+import { writeFile, readFile } from 'fs/promises';+import { join } from 'path';// This will be initialized by server/index.js and set via setAIToolkit()let aiToolkitInstance = null;@@ -15,9 +18,95 @@ export async function createRun(options) {return aiToolkitInstance.services.runner.createRun(options);}+/**+ * Override executeCliRun to fix shell security issue+ * This removes 'shell: true' which causes DEP0190 warning and potential security issues+ */export async function executeCliRun(runId, provider, prompt, workspacePath, onData, onComplete, timeout) {if (!aiToolkitInstance) throw new Error('AI Toolkit not initialized');- return aiToolkitInstance.services.runner.executeCliRun(runId, provider, prompt, workspacePath, onData, onComplete, timeout);++ const runsPath = join(aiToolkitInstance.config.dataDir || './data', 'runs');+ const runDir = join(runsPath, runId);+ const outputPath = join(runDir, 'output.txt');+ const metadataPath = join(runDir, 'metadata.json');++ const startTime = Date.now();+ let output = '';++ // Build command with args - NO shell: true+ const args = [...(provider.args || []), prompt];+ console.log(`🚀 Executing CLI: ${provider.command} ${args.join(' ')}`);+ console.log(`📝 Prompt length: ${prompt.length} chars, first 100: ${prompt.substring(0, 100)}`);++ const childProcess = spawn(provider.command, args, {+ cwd: workspacePath,+ env: { ...process.env, ...provider.envVars }+ // Removed shell: true - this fixes the security warning and ensures proper argument handling+ });++ // Track active run (store on the runner service itself for stopRun to access)+ if (!aiToolkitInstance.services.runner._portosActiveRuns) {+ aiToolkitInstance.services.runner._portosActiveRuns = new Map();+ }+ aiToolkitInstance.services.runner._portosActiveRuns.set(runId, childProcess);++ // Call hooks+ aiToolkitInstance.config.hooks?.onRunStarted?.({ runId, provider: provider.name, model: provider.defaultModel });++ // Set timeout+ const timeoutHandle = setTimeout(() => {+ if (childProcess && !childProcess.killed) {+ console.log(`⏱️ Run ${runId} timed out after ${timeout}ms`);+ childProcess.kill('SIGTERM');+ }+ }, timeout);++ childProcess.stdout?.on('data', (data) => {+ const text = data.toString();+ output += text;+ onData?.(text);+ });++ childProcess.stderr?.on('data', (data) => {+ const text = data.toString();+ output += text;+ onData?.(text);+ });++ childProcess.on('close', async (code) => {+ clearTimeout(timeoutHandle);+ aiToolkitInstance.services.runner._portosActiveRuns?.delete(runId);++ await writeFile(outputPath, output);++ const metadataStr = await readFile(metadataPath, 'utf-8').catch(() => '{}');+ const metadata = metadataStr ? JSON.parse(metadataStr) : {};+ metadata.endTime = new Date().toISOString();+ metadata.duration = Date.now() - startTime;+ metadata.exitCode = code;+ metadata.success = code === 0;+ metadata.outputSize = Buffer.byteLength(output);++ // Analyze errors if the run failed (delegate to toolkit's error detection)+ if (!metadata.success && aiToolkitInstance.services.errorDetection) {+ const errorAnalysis = aiToolkitInstance.services.errorDetection.analyzeError(output, code);+ metadata.error = errorAnalysis.message || `Process exited with code ${code}`;+ metadata.errorCategory = errorAnalysis.category;+ metadata.errorAnalysis = errorAnalysis;+ }++ await writeFile(metadataPath, JSON.stringify(metadata, null, 2));++ if (metadata.success) {+ aiToolkitInstance.config.hooks?.onRunCompleted?.(metadata, output);+ } else {+ aiToolkitInstance.config.hooks?.onRunFailed?.(metadata, metadata.error, output);+ }++ onComplete?.(metadata);+ });++ return runId;}export async function executeApiRun(runId, provider, model, prompt, workspacePath, screenshots, onData, onComplete) {