T09 · Insecure Skill Coding Practices
- Location
scripts/quick_scrape.sh:42- Finding
Command Injection Through Unvalidated Bash Arithmetic Input
- Content
View full analysis
' ``` 3. Line 10 stores the argument in `DAYS` without validation. 4. Line 42 places the value into the arithmetic loop condition. 5. Bash evaluates the crafted arithmetic expression, potentially executing embedded command-substitution behavior. 6. Any resulting command runs under the account and permissions of the user or Agent that invoked the Skill. A simpler availability attack ...[truncated 782 chars]- Remediation
View remediation
&2 exit 2 fi if (( DAYS < 1 || DAYS > 365 )); then echo "DAYS must be between 1 and 365." >&2 exit 2 fi for ((i = 0; i < DAYS; i++)); do DATE=$(date -d "$i days ago" +%Y-%m-%d) curl --fail --silent --show-error --max-time 15 \ "https://www.moe.gov.cn/jyb_xxgk/" | grep "$DATE" | grep -oP 'title="[^"]*"' | head -2 done ``` Additional hardening measures: 1. Reject signs, whitespace, arithmetic operators, variable names, array syntax, and command-substitution characters by using the strict `^[0-9]+$` allowlist. 2. Enforce a conservative upper bound to prevent excessive loops and outbound requests. 3. Add `curl` connection and total timeouts. 4. Consider downloading the target page once before the loop and searching the cached response for each date, rather than issuing one request per day. 5. Enable defensive shell options such as `set -euo pipefail`, while handling expected nonzero `grep` results appropriately. ]]>
