T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:147
- Finding
- User-Controlled Values Embedded into Generated Bash and Python Code## Vulnerability Details **File Location**: `SKILL.md`, lines 147-166 **Vulnerability Type**: Command and code injection through unsafe script generation **Risk Level**: High ### Vulnerable Code ```bash TMPDIR=$(mktemp -d) # Expand ALL dimensions from the user's request: NIGHTS=(3 4 5) # e.g. "3-5 night trips" → 3, 4, 5 DESTINATIONS=("CDG" "PRG") # e.g. "Paris or Prague" → CDG, PRG DATES=("2026-05-01" "2026-05-02" "2026-05-03") # expand to all dates in range for DEST in "${DESTINATIONS[@]}"; do for N in "${NIGHTS[@]}"; do for DATE in "${DATES[@]}"; do RETURN=$(python3 -c "from datetime import datetime,timedelta; print((datetime.strptime('$DATE','%Y-%m-%d')+timedelta(days=$N)).strftime('%Y-%m-%d'))") curl -s -X POST "https://google-flights-live-api.p.rapidapi.com/api/google_flights/roundtrip/v1" \ -H "Content-Type: application/json" \ -H "x-rapidapi-host: google-flights-live-api.p.rapidapi.com" \ -H "x-rapidapi-key: $RAPIDAPI_KEY" \ -d "{\"departure_date\": \"$DATE\", \"return_date\": \"$RETURN\", \"from_airport\": \"TLV\", \"to_airport\": \"$DEST\", \"currency\": \"usd\"}" \ -o "$TMPDIR/${DEST}_${N}n_${DATE}.json" & done done done ``` ### Technical Analysis The Skill instructs the agent to generate and execute a shell script from dimensions derived from the user's request. The generated values are placed into several syntactic contexts without a documented validation or safe-serialization boundary: - `DATE` is interpolated directly into Python source passed to `python3 -c`. - `N` is interpolated as an unquoted Python expression in `timedelta(days=$N)`. - `DATE`, `RETURN`, and `DEST` are manually interpolated into JSON rather than encoded by a JSON serializer. - `DEST`, `N`, and `DATE` are used to construct output filenames. - The generated `DATES`, `NIGHTS`, and `DESTINATIONS` array declarations are themselves execut ...[truncated 2196 chars]
- Remediation
- ## Remediation Suggestions 1. Replace generated shell code with a fixed, reviewed implementation whose structure cannot be changed by user input. 2. Validate all dates against a strict `YYYY-MM-DD` format and confirm them through a date parser before execution. 3. Accept night counts only as bounded decimal integers and reject signs, expressions, whitespace, and metacharacters. 4. Validate airport and airline codes with an allowlist such as `^[A-Z]{3}$` after mapping city names to canonical IATA codes. 5. Pass dynamic values to Python through positional arguments or standard input rather than interpolating them into `python3 -c` source. 6. Construct request bodies with a JSON serializer, for example `jq -n --arg`, instead of manual quoting. 7. Use generated opaque identifiers for temporary filenames rather than incorporating user-controlled values. 8. Use Bash argument arrays and quote every expansion. Do not generate Bash array declarations from raw user text. 9. Add cleanup through `trap 'rm -rf -- "$TMPDIR"' EXIT` so temporary data is removed on errors and interruption. 10. Update the README to accurately disclose that the Skill executes local tools and generated request orchestration logic.
