T09 · Insecure Skill Coding Practices
- Location
scripts/ha-setup.sh:29- Finding
Arbitrary Command Execution Through Unsafe Shell Configuration Generation
- Content
View full analysis
Long-Lived Access Tokens > Create Token)" read -s -p "HA_TOKEN: " HA_TOKEN echo if [ -z "$HA_TOKEN" ]; then echo "Error: HA_TOKEN cannot be empty" exit 1 fi # Save configuration cat > ~/.homeassistant.conf << EOF # Home Assistant Configuration # Generated on $(date) export HA_URL="$HA_URL" export HA_TOKEN="$HA_TOKEN" EOF chmod 600 ~/.homeassistant.conf echo echo "=== Configuration saved to ~/.homeassistant.conf ===" echo echo "To use these settings, run:" echo " source ~/.homeassistant.conf" echo echo "Or add to your ~/.bashrc:" echo " source ~/.homeassistant.conf" echo echo "Testing API connection..." source ~/.homeassistant.conf ``` The script also sources an existing configuration without validating it: ```bash if [ -f ~/.homeassistant.conf ]; then echo "Found existing config: ~/.homeassistant.conf" source ~/.homeassistant.conf ``` ### Technical Analysis `HA_URL` and `HA_TOKEN` are read dir ...[truncated 2499 chars]- Remediation
View remediation
"$CONFIG_FILE" ``` Parsing data rather than sourcing code remains preferable. 3. Do not automatically source the newly generated file. Test the API with the in-memory variables already collected by the script. 4. Before reading an existing configuration, reject symbolic links and verify that the file is a regular file owned by the expected user with restrictive permissions. 5. Validate `HA_URL` using a strict URL parser or allowlist. Reject newlines, carriage returns, shell metacharacters, embedded credentials, and unsupported schemes. 6. Create the configuration atomically with restrictive permissions from the outset, for example by setting `umask 077` and writing to a securely created temporary file before renaming it. 7. Add regression tests using quotes, command substitutions, semicolons, newlines, and backticks to confirm that configuration input can never be interpreted as shell code. ]]>
