T09 · Insecure Skill Coding Practices
- Location
scripts/shellmail.sh:107- Finding
Command Injection Through Unvalidated Bash Arithmetic Expansion
- Content
View full analysis
&2)0]' ``` When Bash evaluates the timeout expression, the embedded command substitution may execute before the API request is issued. ### Attack Path 1. An attacker controls or influences the value used for the `otp --wait` option, such as through an untrusted request, copied command, or prompt-injected email content that is incorrectly treated as an instruction. 2. The agent invokes `scripts/shellmail.sh otp --wait` with the crafted arithmetic expression. 3. The value is interpolated into Bash arithmetic expansion without numeric validation. 4. Bash evaluates the malicious expression and executes its embedded command substitution. 5. The command runs with the same operating-system ...[truncated 799 chars]- Remediation
View remediation
&2 exit 1 fi if (( 10#$WAIT > 300 )); then echo "Error: --wait must not exceed 300 seconds" >&2 exit 1 fi PARAMS="${PARAMS}&timeout=$((10#$WAIT * 1000))" shift 2 ;; ``` Additional hardening should include: 1. Check that every option requiring a value has a following argument before accessing `$2`. 2. Apply strict numeric validation to `--limit` as well, even though it is placed into a URL rather than arithmetic expansion. 3. Reject unknown options instead of silently ignoring them. 4. Add regression tests using arithmetic expressions, command substitutions, missing values, negative numbers, and oversized values. 5. Ensure instructions obtained from mailbox contents are always treated as untrusted data and never copied into command arguments without validation. ]]>
