🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(security): denylist loader-hijack env vars in terminal_create (audit_1776853149979)
Reuvenfb256ac596e6
diff --git a/v3/@claude-flow/cli/src/mcp-tools/terminal-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/terminal-tools.tsindex 97eeee55ee..a3d5749a93 100644--- a/v3/@claude-flow/cli/src/mcp-tools/terminal-tools.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/terminal-tools.ts@@ -6,7 +6,7 @@import { type MCPTool, getProjectCwd } from './types.js';import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';-import { validateIdentifier, validatePath, validateText } from './validate-input.js';+import { validateEnv, validateIdentifier, validatePath, validateText } from './validate-input.js';import { join } from 'node:path';import { execSync } from 'node:child_process';@@ -77,7 +77,7 @@ export const terminalTools: MCPTool[] = [},},handler: async (input) => {- // Validate user-provided input (#1425)+ // Validate user-provided input (#1425, audit_1776853149979)if (input.name) {const v = validateText(input.name, 'name', 256);if (!v.valid) return { success: false, error: v.error };@@ -86,6 +86,11 @@ export const terminalTools: MCPTool[] = [const v = validatePath(input.workingDir, 'workingDir');if (!v.valid) return { success: false, error: v.error };}+ // env is merged into execSync's process env on every command; reject+ // loader/runtime hijack vars (LD_PRELOAD, NODE_OPTIONS, …) and enforce+ // POSIX-shaped names + null-byte-free values.+ const vEnv = validateEnv(input.env, 'env');+ if (!vEnv.valid) return { success: false, error: vEnv.error };const store = loadTerminalStore();const id = `term-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;@@ -98,7 +103,7 @@ export const terminalTools: MCPTool[] = [lastActivity: new Date().toISOString(),workingDir: (input.workingDir as string) || getProjectCwd(),history: [],- env: (input.env as Record<string, string>) || {},+ env: vEnv.sanitized,};store.sessions[id] = session;diff --git a/v3/@claude-flow/cli/src/mcp-tools/validate-input.ts b/v3/@claude-flow/cli/src/mcp-tools/validate-input.tsindex adc690bbd9..3535007354 100644--- a/v3/@claude-flow/cli/src/mcp-tools/validate-input.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/validate-input.ts@@ -117,6 +117,70 @@ export function validateText(value: unknown, label: string, maxLen = 10_000): Vareturn { valid: true, sanitized };}+/**+ * Names that let an attacker pivot a child process before any user code runs:+ * shared-library injection on Linux/macOS, Node hooks, and command resolution.+ *+ * audit_1776853149979: terminal_create previously merged caller-supplied env+ * straight into execSync's environment for every subsequent command in the+ * session. Setting LD_PRELOAD or NODE_OPTIONS via that path is functionally+ * equivalent to remote code execution, so the env input needs an allowlist+ * shape and a denylist on these specific names.+ */+const DENYLISTED_ENV_NAMES = new Set([+ 'LD_PRELOAD',+ 'LD_LIBRARY_PATH',+ 'LD_AUDIT',+ 'DYLD_INSERT_LIBRARIES',+ 'DYLD_LIBRARY_PATH',+ 'DYLD_FALLBACK_LIBRARY_PATH',+ 'DYLD_FORCE_FLAT_NAMESPACE',+ 'NODE_OPTIONS',+ 'NODE_PATH',+]);+const ENV_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;++export interface EnvValidationResult {+ valid: boolean;+ sanitized: Record<string, string>;+ error?: string;+}++/**+ * Validate a Record<string,string> of environment variables: enforce POSIX+ * names, reject hijack-prone names (LD_PRELOAD, NODE_OPTIONS, …), forbid null+ * bytes in values, and cap value length so a malicious caller can't bloat the+ * stored session past reasonable bounds.+ */+export function validateEnv(value: unknown, label = 'env'): EnvValidationResult {+ if (value === undefined || value === null) {+ return { valid: true, sanitized: {} };+ }+ if (typeof value !== 'object' || Array.isArray(value)) {+ return { valid: false, sanitized: {}, error: `${label} must be an object of string→string` };+ }+ const out: Record<string, string> = {};+ for (const [name, rawVal] of Object.entries(value as Record<string, unknown>)) {+ if (!ENV_NAME_RE.test(name)) {+ return { valid: false, sanitized: {}, error: `${label} key "${name}" is not a valid POSIX env name` };+ }+ if (DENYLISTED_ENV_NAMES.has(name)) {+ return { valid: false, sanitized: {}, error: `${label} key "${name}" is denylisted (loader/runtime hijack)` };+ }+ if (typeof rawVal !== 'string') {+ return { valid: false, sanitized: {}, error: `${label}["${name}"] must be a string` };+ }+ if (rawVal.length > 32_768) {+ return { valid: false, sanitized: {}, error: `${label}["${name}"] exceeds 32768 characters` };+ }+ if (rawVal.includes('\0')) {+ return { valid: false, sanitized: {}, error: `${label}["${name}"] contains a null byte` };+ }+ out[name] = rawVal;+ }+ return { valid: true, sanitized: out };+}+/*** Assert validation or throw with a structured error.*/