T09 · Insecure Skill Coding Practices
- Location
research_assistant.sh:56- Finding
Arbitrary Command Execution Through Unvalidated --max Arithmetic Expression
- Content
View full analysis
- Remediation
View remediation
&2 exit 1 } MAX="$2" [[ "$MAX" =~ ^[0-9]+$ ]] || { echo "Invalid --max value: expected a non-negative integer" >&2 exit 1 } shift 2 ;; ``` For defense in depth, validate all enumerated and value-bearing options after parsing: ```bash [[ "$MAX" =~ ^[0-9]+$ ]] || { echo "Invalid --max value" >&2 exit 1 } case "$MODE" in append|prepend) ;; *) echo "Invalid --mode: expected append or prepend" >&2 exit 1 ;; esac ``` Additional hardening measures: 1. Check that each option requiring a value has another argument available before reading `$2`. 2. Do not place untrusted strings in Bash arithmetic contexts. 3. If this script is invoked by an agent, service, or wrapper, pass arguments as a structured argument array rather than constructing a shell command string. 4. Add regression tests that reject arithmetic syntax, command substitutions, signs, whitespace, and non-decimal values for `--max`. 5. Run the script with the minimum filesystem and application permissions needed to process Bear notes. ]]>
