T09 · Insecure Skill Coding Practices
- Location
test-skill.js:9- Finding
Shell Command Injection Through OPENCLAW_ROOT
- Content
View full analysis
Vulnerability Details
File Location:
test-skill.js, lines 9–24
Vulnerability Type: OS command injection caused by constructing a shell command with an environment-controlled path
Risk Level: HighVulnerable Code
javascript const { execSync } = require('child_process'); const path = require('path'); // Get OpenClaw root directory const openclawRoot = process.env.OPENCLAW_ROOT || 'D:\\OpenClaw'; const validatorPath = path.join(openclawRoot, '.openclaw', 'skills', 'agent-config-validator', 'src', 'validator.js'); console.log('🧪 Agent Config Validator - OpenClaw integration test\n'); console.log(`OpenClaw root directory: ${openclawRoot}`); console.log(`Validator path: ${validatorPath}\n`); try { // Run validator const result = execSync( `node "${validatorPath}" --verbose`, { cwd: openclawRoot, encoding: 'utf-8', stdio: 'inherit' } );Technical Analysis
The script reads
OPENCLAW_ROOTfrom the process environment and uses it to buildvalidatorPath. It then interpolates that path into a command string passed tochild_process.execSync().By default,
execSync()executes command strings through a system shell. Consequently, shell metacharacters embedded in the environment-controlled path may be interpreted as command syntax rather than as part of a literal filename. Wrapping the path in double quotes does not provide reliable security because an attacker may inject quote characters and platform-specific shell operators to terminate the quoted argument and append another command.path.join()only constructs and normalizes a filesystem path. It does not escape input for use in a shell command and therefore does not prevent this vulnerability.Exploitation requires the attacker to control or influence
OPENCLAW_ROOTin the environment of a process that runstest-skill.js.Attack Path
- An attacker gains control of the
OPENCLAW_ROOTenviron ...[truncated 1348 chars]
- An attacker gains control of the
- Remediation
View remediation
Remediation Suggestions
Eliminate shell interpretation by invoking Node.js with a fixed executable and a separate argument array:
javascript const { execFileSync } = require('child_process'); const path = require('path'); const fs = require('fs'); const openclawRoot = path.resolve( process.env.OPENCLAW_ROOT || 'D:\\OpenClaw' ); const validatorPath = path.join( openclawRoot, '.openclaw', 'skills', 'agent-config-validator', 'src', 'validator.js' ); if (!fs.existsSync(validatorPath)) { throw new Error(`Validator not found: ${validatorPath}`); } execFileSync( process.execPath, [validatorPath, '--verbose'], { cwd: openclawRoot, encoding: 'utf-8', stdio: 'inherit', shell: false } );Additional hardening measures:
- Resolve the configured root with
path.resolve()before use. - Verify that the root and validator file exist and have the expected file types.
- If the deployment has a known trusted OpenClaw directory, enforce that the resolved path remains within it.
- Do not attempt to solve the issue with manual shell escaping; avoiding the shell is more robust and portable.
- Restrict who can set environment variables in CI jobs, scheduled tasks, and service definitions that execute the test script.
- Add a regression test using paths containing spaces, quotes, and shell metacharacters to ensure they are handled strictly as arguments.
- Resolve the configured root with
