T09 · Insecure Skill Coding Practices
- Location
scripts/run.sh:31- Finding
Arbitrary Command Execution Through HEALTHCHECK_CMD
- Content
View full analysis
Vulnerability Details
File Location:
scripts/run.sh, lines 31–38
Vulnerability Type: Command injection through unsafe command-string execution
Risk Level: HighVulnerable Code:
bash HC_DEFAULT="$HOME/.openclaw/workspace/skills/healthcheck/healthcheck.sh" HEALTH_CMD="${HEALTHCHECK_CMD:-}" if [ -z "$HEALTH_CMD" ] && [ -f "$HC_DEFAULT" ]; then HEALTH_CMD="bash $HC_DEFAULT --json"; fi HEALTH_RAW=""; HEALTH_OK=0 if [ -n "$HEALTH_CMD" ]; then HEALTH_RAW=$($HEALTH_CMD 2>/dev/null) if [ -n "$HEALTH_RAW" ] && printf '%s' "$HEALTH_RAW" | jq -e 'type=="object"' >/dev/null 2>&1; then HEALTH_OK=1 fi fiTechnical Analysis
HEALTHCHECK_CMDis read from the process environment and expanded directly inside command substitution. Shell word splitting turns the supplied string into an executable and arguments without enforcing an allowlist or trusted executable path.For example, a value structured as
sh -c COMMANDcan invoke an arbitrary shell command. The JSON validation occurs only after execution and therefore does not protect against malicious commands.When the environment variable is unset, the script also automatically executes
$HOME/.openclaw/workspace/skills/healthcheck/healthcheck.sh. This is a mutable user-workspace location, and the script performs no ownership, permission, integrity, or symlink checks before execution.Attack Path
- An attacker gains the ability to set
HEALTHCHECK_CMDin the CI job, hook environment, scheduler configuration, or parent process. - The attacker assigns a command such as a shell interpreter with a
-cargument and an attacker-selected payload. - A user or automated system invokes
scripts/run.sh. - Line 37 executes the attacker-selected command.
- The payload runs with the operating-system privileges and environment access of the PR autocheck process.
An alternative path is to replace or redirect t ...[truncated 582 chars]
- An attacker gains the ability to set
- Remediation
View remediation
Remediation Suggestions
- Do not execute a free-form command string from an environment variable.
- Configure a trusted executable path separately and invoke it through a Bash array with fixed arguments.
- If customization is required, accept only a validated executable path and pass arguments through separate, explicitly parsed fields.
- Require the executable to be a regular file owned by an expected user, not group- or world-writable, and not a symbolic link.
- Avoid automatically executing scripts from mutable workspace directories. Bundle the health checker with the Skill or verify its integrity before execution.
- Run the health check under a restricted account or sandbox with a minimal environment, filesystem access, and network access.
- Apply an execution timeout and validate the returned JSON only as output validation, not as an execution security control.
