T09 · Insecure Skill Coding Practices
- Location
scripts/insurance.sh:350- Finding
Arbitrary Command Execution Through Unvalidated Arithmetic Input
- Content
View full analysis
}" local coverage="${2:?Please provide coverage}" local years="${3:?Please provide coverage duration}" local age_factor premium if [ "$age" -lt 30 ]; then age_factor="0.8" elif [ "$age" -lt 40 ]; then age_factor="1.0" elif [ "$age" -lt 50 ]; then age_factor="1.5" else age_factor="2.5"; fi premium=$(echo "scale=0; $coverage * 0.0015 * $age_factor" | bc) local total total=$(echo "$premium * $years" | bc) cat <- Remediation
View remediation
&2 exit 1 fi } require_positive_integer "age" "$age" require_positive_integer "coverage" "$coverage" require_positive_integer "years" "$years" ``` Additional hardening should include: 1. Enforce realistic upper and lower bounds for age, coverage, income, and duration. 2. Convert validated values to canonical decimal integers before arithmetic use. 3. Do not treat `bc` as a validation or sanitization layer. 4. Prefer passing fixed-format operands to `bc` only after strict allowlist validation. 5. Add regression tests containing shell metacharacters, command substitutions, array syntax, whitespace, signs, decimals, and extremely large values. 6. Reject invalid insurance types rather than silently applying a default rate. ]]>
