T09 · Insecure Skill Coding Practices
Error
- Location
- send_image.mjs:67
- Finding
- Shell Command Injection Through Caller-Controlled CLI Arguments<![CDATA[ ## Vulnerability Details **File Location**: `send_image.mjs`, lines 67-74 **Vulnerability Type**: OS command injection **Risk Level**: High ### Vulnerable Code ```js const args = ['message', 'send', '--media', imagePath, '--channel', channel, '--target', target]; if (message) args.push('--message', message); const proc = spawn('openclaw', args, { stdio: 'inherit', shell: true }); ``` ### Technical Analysis The `channel`, `target`, and `message` values originate directly from command-line arguments. The media path is also derived from a caller-supplied source path. These values are passed to `child_process.spawn()` with `shell: true`. Enabling `shell` causes the command and its arguments to be interpreted through a system shell. Shell metacharacters embedded in an argument may consequently be treated as command syntax rather than as literal data. Supplying arguments as an array does not provide the expected direct-process safety when shell execution is explicitly enabled. The program does not require shell functionality because `openclaw` can be executed directly with the argument array. ### Attack Path 1. An attacker obtains the ability to invoke the Skill or influence one of its documented parameters. 2. The attacker supplies shell syntax in `channel`, `target`, `message`, or a caller-controlled filename. 3. `main()` passes the value to `sendImage()`. 4. `sendImage()` inserts the value into the `args` array without validation. 5. `spawn()` starts `openclaw` with `shell: true`. 6. The operating-system shell interprets applicable metacharacters and may execute an additional attacker-selected command. The exact metacharacters and payload form depend on the operating system and configured shell. ### Impact Assessment Successful exploitation permits arbitrary command execution with the same operating-system identity and privileges as the Skill process. This may allow an attacker to: - Read or modify files accessible to the Agent. - Acces ...[truncated 465 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Disable shell interpretation and execute the binary directly: ```js const proc = spawn('openclaw', args, { stdio: 'inherit', shell: false }); ``` Additional hardening should include: 1. Validate `channel` against an explicit allowlist of supported channel identifiers. 2. Validate `target` according to the selected channel's documented identifier format. 3. Treat `message` exclusively as data and impose a reasonable length limit. 4. Resolve and validate the media path before passing it to the CLI. 5. Consider using an absolute, trusted path to the `openclaw` executable to reduce executable-path ambiguity. 6. Add tests containing spaces, quotes, command separators, substitutions, and redirection characters to verify that all values remain literal arguments. ]]>
