T09 · Insecure Skill Coding Practices
Error
- Location
- install.cjs:110
- Finding
- Command Injection Through CLI Fallback Commands<![CDATA[ ## Vulnerability Details **File Location**: `install.cjs`, lines 110-113 and 233-238 **Vulnerability Type**: OS command injection through unsanitized shell interpolation **Risk Level**: High ### Vulnerable Code ```javascript const output = execSync(`npx clawhub search ${query} 2>&1`, { encoding: 'utf-8', cwd: SKILLS_DIR }); ``` ```javascript execSync(`npx clawhub install ${skillName} --force`, { encoding: 'utf-8', cwd: SKILLS_DIR, stdio: 'inherit' }); ``` ### Technical Analysis The `query` and `skillName` values originate from command-line arguments and are inserted directly into command strings passed to `execSync`. Because `execSync` executes the string through a shell, shell metacharacters contained in either value are interpreted as command syntax rather than literal argument data. The vulnerable commands are reached when the corresponding direct API operation fails. No allowlist validation or shell escaping is applied before execution. ### Attack Path 1. An attacker persuades a user or automation process to invoke `search`, `install`, or `install-batch` with a crafted query or skill name containing shell metacharacters. 2. The attacker causes or waits for the ClawHub API request or installation process to fail. 3. The error handler invokes the ClawHub CLI fallback. 4. The crafted value is interpolated into the shell command. 5. The shell interprets the injected syntax and executes attacker-selected local commands under the installer's user account. ### Impact Assessment Successful exploitation provides arbitrary command execution with all privileges held by the user running the installer. This can allow reading or modifying user-accessible files, stealing credentials, altering OpenClaw configuration, installing malicious skills, or fully compromising the account. If the installer is run with elevated privileges, the impact extends to system-level compromise. ]]>
- Remediation
- <![CDATA[ ## Remediation Suggestions - Replace shell-based `execSync` calls with `execFileSync` or `spawnSync`, passing each argument separately: ```javascript execFileSync('npx', ['clawhub', 'search', query], { encoding: 'utf8', cwd: SKILLS_DIR }); execFileSync('npx', ['clawhub', 'install', skillName, '--force'], { cwd: SKILLS_DIR, stdio: 'inherit' }); ``` - Validate skill identifiers against a strict allowlist, such as `^[A-Za-z0-9._-]+$`. - Reject control characters, shell metacharacters, path separators, and traversal sequences. - Avoid invoking `npx` dynamically where possible. Resolve and execute a trusted, preinstalled ClawHub binary. - Treat API failure as an explicit error unless fallback behavior is necessary and securely implemented. ]]>
