T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/install.sh:199
- Finding
- Command Injection Through Generated Startup Scripts<![CDATA[ ## Vulnerability Details **File Location**: `scripts/install.sh:52-55`, `scripts/install.sh:141-145`, `scripts/install.sh:199-205`, and `scripts/install.sh:231-237` **Vulnerability Type**: Shell command injection through unsafe code generation **Risk Level**: High ### Vulnerable Code User-controlled configuration is collected without restrictive validation: ```bash read -r -p " Your public URL (e.g. https://portal.yourdomain.com): " PUBLIC_URL if [ -z "$PUBLIC_URL" ]; then echo "✗ PUBLIC_URL is required." exit 1 fi ``` ```bash read -r -p "→ Bot name (press Enter for 'Beware'): " BOT_NAME BOT_NAME="${BOT_NAME:-Beware}" read -r -p "→ Bot emoji (press Enter for '🌀'): " BOT_EMOJI BOT_EMOJI="${BOT_EMOJI:-🌀}" ``` These values are then inserted directly into generated shell scripts: ```bash cat >> "$START_SERVER" <<STARTSCRIPT PUBLIC_URL=$PUBLIC_URL \\ GATEWAY_TOKEN="\$GATEWAY_TOKEN" \\ SETUP_TOKEN="\$SETUP_TOKEN" \\ BOT_NAME="$BOT_NAME" \\ BOT_EMOJI="$BOT_EMOJI" \\ ${TTS_LINE} node server.js STARTSCRIPT ``` The same unsafe interpolation occurs in `start.sh`: ```bash cat >> "$START_ALL" <<ALLSCRIPT_BODY PUBLIC_URL=$PUBLIC_URL \\ GATEWAY_TOKEN="\$GATEWAY_TOKEN" \\ SETUP_TOKEN="\$SETUP_TOKEN" \\ BOT_NAME="$BOT_NAME" \\ BOT_EMOJI="$BOT_EMOJI" \\ ${TTS_LINE} node "$INSTALL_DIR/server.js" &>/tmp/clawtime.log & ``` ### Technical Analysis The installer constructs executable shell source using values supplied interactively by the user. `PUBLIC_URL` is emitted without quoting, while `BOT_NAME` and `BOT_EMOJI` are placed inside double quotes without escaping embedded quotation marks, command substitutions, backticks, line breaks, or shell control operators. Here-document expansion occurs while the installer generates each file, and the resulting file is later parsed again as shell syntax. Consequently, input that changes the syntactic structure of an assignment can add arbitrary commands to `start-server.sh` or `start.sh`. This is a code-generation ...[truncated 2095 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Do not generate executable shell source by directly interpolating user input. 2. Store non-secret configuration in a structured format such as JSON and have the application parse it without `eval` or shell sourcing. 3. If shell-script generation is unavoidable, serialize every value using a shell-aware escaping mechanism such as: ```bash printf 'PUBLIC_URL=%q\n' "$PUBLIC_URL" >> "$START_SERVER" printf 'BOT_NAME=%q\n' "$BOT_NAME" >> "$START_SERVER" printf 'BOT_EMOJI=%q\n' "$BOT_EMOJI" >> "$START_SERVER" ``` 4. Validate `PUBLIC_URL` using a URL parser and require: - The `https` scheme. - A valid hostname. - No credentials, control characters, whitespace, shell syntax, or unexpected path/query components. 5. Apply explicit length and character restrictions to `BOT_NAME` and `BOT_EMOJI`. 6. Prefer passing configuration as fixed argument-array elements or through a securely generated environment file parsed without shell evaluation. 7. Add automated tests using quotation marks, command substitutions, backticks, newlines, semicolons, pipes, and redirection characters to verify that generated configuration cannot change shell syntax. ]]>
