T09 · Insecure Skill Coding Practices
- Location
scripts/setup.sh:17- Finding
Shell Command Injection Through Generated Environment Configuration
- Content
View full analysis
/dev/null || echo "$PYTHON_INPUT") else PYTHON_PATH="$PYTHON_INPUT" fi ``` ```bash cat > "$OPENCLAW_ENV" << ENVEOF #!/bin/bash # === wsl-windows-bridge environment === # Auto-generated at $(date -u +%Y-%m-%dT%H:%M:%SZ) export WIN_BIN="\$HOME/.openclaw/bin" export PATH="\$WIN_BIN:\$PATH" export WIN_ROOT="$WIN_ROOT" export WIN_ANACONDA="$WIN_ROOT/app/anaconda" export WIN_SCRIPTS="$WIN_ROOT/app/scripts" export WIN_PROJECT="$WIN_ROOT/app/project" export WIN_PYTHON="$PYTHON_PATH" export WIN_PS="/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" export WIN_CMD="/mnt/c/Windows/System32/cmd.exe" ``` ```bash source "$OPENCLAW_ENV" 2>/dev/null ``` ### Technical Analysis The installer accepts an interactive Windows root or Python path and interpolates that value directly into an executable shell configuration file. No validation or shell-safe escaping is applied before constructing assignments such as: ```bash export WIN_ROOT="$WIN_ROOT" export WIN_PYTHON="$PYTHON_PATH" ``` An input containing a double quote followed by shell syntax can terminate the generated assignment and append ...[truncated 2077 chars]- Remediation
View remediation
"$OPENCLAW_ENV" ``` 2. **Validate input against expected path formats.** Reject control characters and values outside supported WSL or Windows path patterns. Validation should occur before writing the configuration: ```bash if [[ "$PYTHON_INPUT" == *$'\n'* || "$PYTHON_INPUT" == *$'\r'* ]]; then echo "ERROR: Path contains invalid control characters." >&2 exit 1 fi ``` A stricter allowlist should be used where practical. 3. **Do not immediately source generated executable configuration.** Perform verification using local variables or invoke tools directly after validation. This reduces the impact of any future serialization defect. 4. **Prefer a non-executable data format.** Store paths in a format such as JSON and load them with a parser instead of generating shell code from user input. 5. **Write the configuration atomically with restrictive permissions.** Create a temporary file using `mktemp`, set permissions to `0600`, validate its contents, and atomically rename it into place. ]]>
