T09 · Insecure Skill Coding Practices
Note
- Location
- douyin-spark.js:55
- Finding
- Unsafe Shell Command Construction in Browser Command Helper## Vulnerability Details **File Location**: `douyin-spark.js`, lines 55-63 **Vulnerability Type**: OS command injection **Risk Level**: Low ### Vulnerable Code ```js function runBrowserCommand(args) { try { const cmd = `openclaw browser ${args}`; execSync(cmd, { stdio: 'pipe' }); return true; } catch (error) { console.error('浏览器命令执行失败:', error.message); return false; } } ``` ### Technical Analysis The `runBrowserCommand` function concatenates its `args` parameter directly into a command string and passes the resulting value to `child_process.execSync`. By default, `execSync` executes command strings through a system shell. If an attacker can influence `args`, shell metacharacters such as semicolons, command substitutions, pipes, or redirection operators can cause the shell to execute additional commands. For example, an argument containing a legitimate browser operation followed by a shell command could escape the intended `openclaw browser` invocation. The audited version does not call or export `runBrowserCommand`, so no currently reachable exploitation path from the command-line arguments was identified. The vulnerable helper is therefore dormant in the present implementation. It would become exploitable if later connected to CLI parameters, contact data, webpage content, agent-generated values, or other untrusted input without strict validation. ### Attack Path A complete exploitation path would require the dormant helper to become reachable: 1. An application change or integration passes attacker-controlled data to `runBrowserCommand(args)`. 2. The attacker includes shell metacharacters and an additional operating-system command in `args`. 3. The function constructs a single command string: ```text openclaw browser <attacker-controlled content> ``` 4. `execSync` invokes the system shell to interpret that string. 5. The shell executes both the expe ...[truncated 767 chars]
- Remediation
- ## Remediation Suggestions 1. Remove `runBrowserCommand` if it is not required. 2. If command execution is required, avoid invoking a shell. Use `execFileSync` or `spawnSync` with an argument array: ```js const { execFileSync } = require('child_process'); function runBrowserCommand(args) { if (!Array.isArray(args)) { throw new TypeError('Browser arguments must be an array'); } execFileSync('openclaw', ['browser', ...args], { stdio: 'pipe', shell: false }); return true; } ``` 3. Define a strict allowlist of supported browser actions and reject unknown flags, control characters, and unexpected value formats. 4. Do not pass contact names, webpage text, agent-generated strings, or raw CLI parameters into process-execution functions. 5. Prefer a direct OpenClaw API or structured browser-tool interface over spawning a command-line process. 6. Add tests containing shell metacharacters to verify that user-controlled values are treated exclusively as literal arguments.
