T09 · Insecure Skill Coding Practices
- Location
pre-apply-check.sh:97- Finding
Arbitrary Command Execution Through Bash Arithmetic Evaluation
- Content
View full analysis
MAX_DAYS_POSTED )); then disqualify "Job is $DAYS_POSTED days old, exceeds your maximum of $MAX_DAYS_POSTED days" fi ``` ```bash if (( CLIENT_SPEND == 0 )); then warn "Client has \$0 total spend on Upwork — no track record" fi if (( DAYS_POSTED >= 5 )); then warn "Job is $DAYS_POSTED days old — competition may have grown" fi ``` ### Technical Analysis The values supplied through `--budget`, `--client-spend`, and `--days-posted` are stored without validating that they contain only decimal digits. They are subsequently evaluated in Bash arithmetic contexts. Bash arithmetic evaluation does not treat variable contents as inert strings. Values can be recursively interpr ...[truncated 1745 chars]- Remediation
View remediation
&2 exit 2 } is_nonnegative_integer "$CLIENT_SPEND" || { printf '%s\n' "Error: --client-spend must be a non-negative integer." >&2 exit 2 } is_nonnegative_integer "$DAYS_POSTED" || { printf '%s\n' "Error: --days-posted must be a non-negative integer." >&2 exit 2 } ``` Additionally: - Verify that each value-taking option has a following argument before reading `$2`. - Reject signs, whitespace, arithmetic operators, brackets, variable names, and shell metacharacters. - Consider parsing validated decimal values with a language or utility that does not recursively evaluate shell expressions. - Add regression tests using malformed arithmetic expressions and command-substitution payloads. - Enable defensive shell options where compatible, while recognizing that `set -e` or `set -u` does not replace input validation. ]]>
