T09 · Insecure Skill Coding Practices
- Location
scripts/hook-runner.mjs:40- Finding
Arbitrary Shell Command Execution Through Untrusted Hook Configuration
- Content
View full analysis
Vulnerability Details
File Location:
scripts/hook-runner.mjs:40-47
Vulnerability Type: OS command injection through shell-based hook execution
Risk Level: HighVulnerable Code
javascript function runHookCommand(command, env) { return new Promise((resolve) => { const isWindows = process.platform === 'win32'; const shell = isWindows ? 'cmd' : '/bin/sh'; const shellArgs = isWindows ? ['/C', command] : ['-c', command]; const child = spawn(shell, shellArgs, { env: { ...process.env, ...env }, stdio: ['pipe', 'pipe', 'pipe'] });Technical Analysis
Hook definitions are accepted as strings and passed directly to
cmd /Con Windows or/bin/sh -con other platforms. The shell interprets metacharacters, substitutions, redirections, pipelines, and additional commands contained in each hook string.Hook configuration can originate from the
HookRunnerconstructor and, in CLI mode, from theHOOK_PREandHOOK_POSTenvironment variables. Therefore, any party capable of influencing these values can execute arbitrary operating-system commands with the privileges of the Node.js process.The child process also receives a copy of the complete parent environment through
...process.env. Consequently, an untrusted hook can access credentials, API tokens, service endpoints, and other secrets present in the Agent process environment. No executable allowlist, argument separation, sandbox, privilege reduction, or environment filtering is applied.Attack Path
- An attacker gains influence over the Skill configuration, the
HookRunnerconstructor arguments, or theHOOK_PREorHOOK_POSTenvironment variable. - The attacker supplies a hook containing an arbitrary shell payload, such as a command chain, file-read operation, or invocation of another executable.
- A pre-tool or post-tool event calls
runHookCommand()with the attacker-controlled string.
...[truncated 1324 chars]
- An attacker gains influence over the Skill configuration, the
- Remediation
View remediation
Remediation Suggestions
- Replace shell command strings with structured hook definitions containing an approved executable path and an argument array.
- Invoke hooks with
spawn(executable, args, { shell: false }); do not use/bin/sh -corcmd /C. - Validate executable paths against an explicit allowlist and reject relative paths, unexpected interpreters, and writable executables.
- Do not inherit the complete parent environment. Construct a minimal environment containing only variables required by the hook.
- Remove credentials, tokens, proxy secrets, and unrelated service configuration from child-process environments.
- Require explicit administrative approval before enabling or changing hooks.
- Protect configuration sources with appropriate filesystem permissions and deployment controls.
- Execute hooks under a dedicated, low-privilege identity or inside a sandbox with restricted filesystem, process, and network access.
- Apply execution timeouts, output-size limits, and process termination handling to prevent resource exhaustion.
- Record the approved hook identifier rather than logging an untrusted command string.
