T09 · Insecure Skill Coding Practices
- Location
src/agent-roles.js:286- Finding
OS Command Injection Through Unsanitized Task Text
- Content
View full analysis
Vulnerability Details
File Location:
src/agent-roles.js:286-294
Vulnerability Type: OS command injection
Risk Level: HighVulnerable Code
javascript // Try to execute as command try { console.log(`[Executor] Executing as shell command`); const { exec } = require('child_process'); const { promisify } = require('util'); const execAsync = promisify(exec); const { stdout, stderr } = await execAsync(`echo "Task executed: ${task}"`, { cwd: process.cwd(), timeout: 10000 });Technical Analysis
The
taskvalue originates from command-line arguments or a caller ofexecuteTask()and is forwarded toExecutorAgent.executeRoleSpecific(). The code interpolates this untrusted value directly into a command passed tochild_process.exec().Because
exec()invokes a system shell, shell metacharacters and expansions insidetaskare interpreted rather than treated as literal text. Wrapping the value in double quotes does not prevent command substitution using$(...)or backticks. An attacker can also inject a closing quote followed by shell operators.The vulnerable fallback is reached when:
- A tools registry is configured.
- ReAct execution fails or is unavailable.
- The task does not match a registered tool name.
The CLI configures both the external ReAct engine and tools registry, and all supported orchestration modes can dispatch task text to the executor.
Attack Path
- An attacker controls task text supplied through the CLI or programmatic API.
- The CLI parses the text and calls
orchestrator.executeTask(task, ...). - The orchestrator forwards the original task, or a generated subtask containing it, to
ExecutorAgent. - ReAct execution throws or is unavailable.
- No registered tool name matches the task.
- The fallback constructs a shell command containing the untrusted task.
- The shell evaluates injected command substitutions or operators.
For example, task text with the following ...[truncated 870 chars]
- Remediation
View remediation
Remediation Suggestions
Remove shell execution from this fallback. The command only formats a status message, so it should be implemented directly in JavaScript:
javascript return { success: true, result: `Task executed: ${task}`, stderr: null, note: 'Task acknowledged without shell execution' };If process execution is genuinely required in a future implementation:
- Use
execFile()orspawn()with a fixed executable and an argument array. - Keep
shell: false. - Apply a strict allowlist of executable names and supported operations.
- Validate argument types, formats, lengths, and permitted values.
- Do not accept raw command lines from task descriptions.
- Run subprocesses with minimal operating-system privileges.
- Use a dedicated, restricted working directory rather than arbitrary
process.cwd(). - Restrict inherited environment variables to an explicit allowlist.
- Enforce execution timeouts and output-size limits.
- Add regression tests covering
$(), backticks, quotes, semicolons, pipes, redirections, newlines, and logical shell operators.
The external ReAct engine and tools registry imported from outside this project should also enforce independent authorization, path confinement, and argument validation before exposing filesystem or command-execution tools.
- Use
