T09 · Insecure Skill Coding Practices
Warning
- Location
- SKILL.md:31
- Finding
- Shell Command Injection Through Unvalidated CLI Arguments<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 31–56 **Vulnerability Type**: Command injection through unvalidated, user-influenced shell arguments **Risk Level**: Medium ### Vulnerable Code ```md Then pick an `agent-name` based on the purpose. Prefer short, stable ids like: - `beauty`, `coding`, `support`, `ops`, `research`, `personal` Notes: - OpenClaw normalizes names to an agent id (lowercase; invalid characters collapse to `-`). The id cannot be `main` (reserved). - Use the normalized id in the workspace directory: `~/.openclaw/workspace-<agent-id>`. ### 1. Create the agent with exec (non-interactive, JSON) Use the **exec** tool to run the OpenClaw CLI. Non-interactive creation **requires** `--workspace` and `--non-interactive`. Before creating, check whether it already exists: ```bash openclaw agents list --json ``` Before running creation, explicitly ask for confirmation, for example: - `I am ready to run: openclaw agents add <agent-name> --workspace ~/.openclaw/workspace-<agent-id> --non-interactive --json. Run it now?` Only execute the command after the user confirms. Create the agent: ```bash openclaw agents add <agent-name> --workspace ~/.openclaw/workspace-<agent-id> --non-interactive --json ``` Optional flags you can add when needed: - `--model <id>` – default model for this agent. - `--agent-dir <dir>` – agent state dir (default: `~/.openclaw/agents/<id>/agent`). - `--bind <channel[:accountId]>` – route a channel to this agent (repeatable). ``` ### Technical Analysis The Skill directs the agent to construct and execute a shell command using an agent name, normalized agent ID, model ID, directory, and channel binding that may originate from user input. It recommends simple names but does not impose a mandatory allowlist, reject shell metacharacters, require shell-safe quoting, or require an execution interface that passes arguments without invoking a shell. The statement that OpenClaw normalizes agent name ...[truncated 1995 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Require the final normalized agent ID to match a strict allowlist such as: ```regex ^[a-z0-9][a-z0-9-]{0,62}$ ``` Explicitly reject the reserved ID `main`, leading hyphens, empty values, path separators, whitespace, control characters, and shell metacharacters. 2. Validate each optional parameter independently: - Permit only known or strictly formatted model identifiers. - Resolve `--agent-dir` and `--workspace` to approved base directories and reject path traversal. - Define an allowlisted grammar for channel and account identifiers used by `--bind`. 3. Use an execution API that accepts an executable and argument array without invoking a shell, conceptually: ```text executable: openclaw arguments: - agents - add - <validated-agent-name> - --workspace - <validated-workspace-path> - --non-interactive - --json ``` 4. If shell execution is unavoidable, apply robust platform-appropriate quoting to every dynamic argument after validation. Do not rely on manual interpolation or user confirmation as the primary defense. 5. Build the workspace path from the validated normalized ID rather than accepting an arbitrary path. Resolve the resulting path and verify that it remains beneath the intended OpenClaw workspace directory. 6. Update the Skill instructions to require displaying the validated executable and each argument separately before confirmation, and abort when validation fails. ]]>
