T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:20
- Finding
- Shell Command and Argument Injection Through Unvalidated, Unquoted Parameters<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 20–62 and 186–197 **Vulnerability Type**: Shell command injection, argument injection, and unsafe path handling **Risk Level**: High ### Vulnerable Code ```markdown Extract the following fields from user input: - `AGENT_ID`: English ID (e.g. marketing) - `AGENT_NAME`: Agent name (e.g. Marketing Assistant, Alice, WorkBot, etc.) - `BOT_TOKEN`: Telegram Bot Token - `ALLOW_FROM`: allowFrom numeric ID (e.g. 123456789) - `DESCRIPTION`: Role description (e.g. responsible for content marketing and social media) ``` ```bash cp ${CONFIG_PATH} ${CONFIG_PATH}.bak.$(date +%Y%m%d%H%M%S) openclaw agents add ${AGENT_ID} cp ${MAIN_AGENT_DIR}/auth-profiles.json \ ${NEW_AGENT_DIR}/auth-profiles.json cp -r ${MAIN_WORKSPACE}/skills/ \ ${NEW_WORKSPACE}/skills/ cp ${MAIN_WORKSPACE}/USER.md \ ${NEW_WORKSPACE}/USER.md ``` ```bash cat ${CONFIG_PATH} | python3 -m json.tool cp ${CONFIG_PATH}.bak.* ${CONFIG_PATH} chown -R $(stat -c '%U:%G' ${MAIN_WORKSPACE}) ${NEW_WORKSPACE}/ chown -R $(stat -c '%U:%G' ${MAIN_AGENT_DIR}) ${NEW_AGENT_DIR}/ ``` ### Technical Analysis The skill obtains `AGENT_ID` from user input and uses it to derive filesystem paths. It does not specify an enforceable allowlist or escaping procedure before inserting variables into shell commands. Variables including `${AGENT_ID}`, `${CONFIG_PATH}`, `${MAIN_WORKSPACE}`, `${MAIN_AGENT_DIR}`, `${NEW_WORKSPACE}`, and `${NEW_AGENT_DIR}` are expanded without double quotes. If these instructions are executed through a shell, whitespace and shell metacharacters in attacker-influenced values can be interpreted as syntax rather than data. Values beginning with a hyphen may also be interpreted as command options. Unquoted path expansions can undergo word splitting and pathname expansion, potentially affecting files outside the intended target. The recursive `chown` commands increase the severity because manipulated paths or arguments could ...[truncated 1152 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Enforce strict validation before any command execution: - `AGENT_ID`: `^[A-Za-z0-9_-]{1,64}$` - `ALLOW_FROM`: digits only with a documented length limit - Reject control characters, path separators, whitespace, and shell metacharacters. 2. Quote every variable expansion: ```bash openclaw agents add -- "$AGENT_ID" cp -- "$MAIN_AGENT_DIR/auth-profiles.json" "$NEW_AGENT_DIR/auth-profiles.json" ``` 3. Use `--` before path operands where supported to prevent option injection. 4. Canonicalize every derived path and verify that it remains beneath the expected state directory before creating, copying, or changing ownership. 5. Replace interpolated shell commands with structured process APIs that pass arguments as an array without invoking a shell. 6. Avoid recursive ownership changes where possible. If required, verify the target directory, reject symbolic links, and operate only on an expected newly created directory. 7. Run the workflow under a dedicated, minimally privileged operating-system account. ]]>
