T09 · Insecure Skill Coding Practices
- Location
scripts/anchor.sh:65- Finding
Command Injection Through Unvalidated DAYS_BACK Arithmetic Expression
- Content
View full analysis
- Remediation
View remediation
&2 exit 1 fi if (( DAYS_BACK > 365 )); then printf 'Error: --days must not exceed 365.\n' >&2 exit 1 fi ``` Also verify that `--days` has an argument before reading `$2`: ```bash --days) if [[ $# -lt 2 ]]; then printf 'Error: --days requires a value.\n' >&2 exit 1 fi DAYS_BACK="$2" shift 2 ;; ``` Apply validation after parsing so it covers both the environment variable and command-line input. Keep a reasonable upper bound to prevent resource-exhaustion attacks. For additional hardening: - Use `set -euo pipefail`. - Use `readonly` for validated configuration values where practical. - Avoid feeding untrusted strings into Bash arithmetic contexts. - Add tests for missing, negative, zero, malformed, expression-based, and excessively large values. ]]>
