T09 · Insecure Skill Coding Practices
Error
- Location
- lib/checks.sh:327
- Finding
- Arbitrary Local Command Execution Through eval<![CDATA[ ## Vulnerability Details **File Location**: `lib/checks.sh:327-330` **Vulnerability Type**: OS command injection through unrestricted shell evaluation **Risk Level**: Critical ### Vulnerable Code ```bash check_1_25() { if [ -n "${SWITCH_CLI_CMD:-}" ]; then eval "$SWITCH_CLI_CMD" ``` ### Technical Analysis The `SWITCH_CLI_CMD` environment variable is passed directly to Bash's `eval` built-in. `eval` interprets the entire value as shell syntax, including command substitutions, redirections, pipelines, variable expansions, and compound commands. No validation, allowlist, escaping, or argument separation is applied. Consequently, any party able to influence the process environment can execute arbitrary local commands when check `1.25` is selected or included in the default check set. For example: ```bash SWITCH_CLI_CMD='id; cat ~/.ssh/id_rsa' \ PREFLIGHT_CHECKS=1.25 \ bash preflight.sh ``` The vulnerability is particularly severe when the Skill is launched by an automation system that constructs environment variables from user-controlled job parameters. ### Attack Path 1. An attacker gains control of, or injects content into, `SWITCH_CLI_CMD`. 2. A user, Agent, CI worker, or cluster automation service invokes check `1.25`. 3. `check_1_25` passes the environment value to `eval`. 4. Bash parses the attacker-controlled value as executable shell syntax. 5. The payload runs with all permissions and credentials available to the Skill process. ### Impact Assessment Successful exploitation provides arbitrary command execution with the privileges of the invoking account. If the health check is run as `root`, the attacker can obtain complete host control. Potential consequences include: - Reading SSH keys, tokens, configuration files, and other process-accessible secrets. - Modifying or deleting local and mounted filesystem content. - Altering cluster or network configuration. - Installing persistence or additional malicious software. - Pivoting ...[truncated 77 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Remove `eval` entirely. Do not expose an unrestricted shell command through an inherited environment variable. Recommended hardening measures: 1. Implement explicit vendor-specific switch adapters using fixed executable paths and fixed subcommands. 2. Represent command arguments as a Bash array so each argument remains a separate data value: ```bash cmd=(trusted-switch-cli --show-interface-status) "${cmd[@]}" ``` 3. If limited user selection is required, map a small allowlist of symbolic operation names to predefined commands. 4. Reject shell metacharacters, command substitutions, redirections, control characters, and unknown operation names. 5. Run switch checks under a dedicated, minimally privileged account with narrowly scoped credentials. 6. Avoid inheriting security-sensitive configuration from untrusted job or Agent environments. ]]>
