T09 · Insecure Skill Coding Practices
- Location
src/validator.js:131- Finding
Configurable Shell Command Allows Arbitrary Command Execution
- Content
View full analysis
Vulnerability Details
File Location:
src/validator.js:12-15, 126-136
Vulnerability Type: OS command injection and execution of untrusted project scripts
Risk Level: HighVulnerable Code
javascript this.options = { testCommand: options.testCommand || 'npm test', coverageThreshold: options.coverageThreshold || 80, timeout: options.timeout || 60000, ...options };javascript // Run tests const output = execSync(this.options.testCommand, { cwd, encoding: 'utf-8', timeout: this.options.timeout, stdio: ['pipe', 'pipe', 'pipe'] });Technical Analysis
testCommandis accepted through the public constructor options and passed as a single string tochild_process.execSync. String commands executed throughexecSyncare interpreted by a shell, so shell metacharacters, command substitutions, redirections, and command chaining operators contained in an attacker-influenced option can execute additional commands.For example, a value conceptually equivalent to
npm test; attacker-commandwould cause both commands to be interpreted by the shell. The exact payload available depends on the host operating system.Even when the default
npm testvalue is used, validation executes thetestscript from thepackage.jsonincontext.cwd. A malicious or untrusted target project can therefore supply an arbitrary test script. No sandbox, privilege reduction, network restriction, environment filtering, or explicit approval boundary is applied before execution.Attack Path
- An attacker causes the Agent to validate an untrusted project or influences the options passed to
TestValidator. - The attacker either:
- supplies shell syntax in
options.testCommand; or - places a malicious
testscript in the target project'spackage.json.
- supplies shell syntax in
validate()invokesrunTests().runTests()executes the command throughexecSyncin the selected ...[truncated 721 chars]
- An attacker causes the Agent to validate an untrusted project or influences the options passed to
- Remediation
View remediation
Remediation Suggestions
- Replace
execSyncwithexecFileSyncorspawnSync, using a fixed executable and a separately constructed argument array. - Do not accept an unrestricted shell command string. If customization is necessary, allow only predefined test runners and validated argument lists.
- Set
shell: falseexplicitly and reject shell metacharacters rather than attempting to escape arbitrary shell input. - Canonicalize and validate
context.cwd, and require it to remain inside an approved workspace. - Require explicit user approval before running scripts from an untrusted target project's
package.json. - Execute project tests in an isolated subprocess or container with:
- a minimal environment-variable allowlist;
- restricted filesystem mounts;
- disabled or restricted network access;
- resource and process limits;
- a non-privileged operating-system identity.
- Add tests proving that command separators and command-substitution syntax cannot trigger secondary commands.
- Replace
