T09 · Insecure Skill Coding Practices
- Location
scripts/gog-cleanup.sh:65- Finding
Unescaped GOG Metadata Allows HTML Injection into Email Digests
- Content
View full analysis
" email_body+="🧹 GOG Game Cleanup Report
" email_body+="You have ${game_count} installed game(s) that haven't been played in ${STALE_DAYS}+ days:
" email_body+="" email_body+="" for line in "${lines[@]}"; do IFS=$'\t' read -r id name last_played install_path <<< "$line" email_body+="Game Last Played Install Path ${name} ${last_played} ${install_path} - Remediation
View remediation
`, `"`, and `'`. A shell helper can perform the required escaping: ```bash html_escape() { local value=$1 value=${value//&/&} value=${value///>} value=${value//\"/"} value=${value//\'/'} printf '%s' "$value" } ``` Escape each field immediately before constructing the table row: ```bash safe_name=$(html_escape "$name") safe_last_played=$(html_escape "$last_played") safe_install_path=$(html_escape "$install_path") email_body+="${safe_name}${safe_last_played}${safe_install_path}" ``` Additional hardening measures: 1. Prefer a structured HTML-generation library or template engine that escapes interpolated values by default. 2. Consider sending a plain-text digest if rich HTML formatting is not essential. 3. Validate the expected types and formats of all fields in `gog_library.json` before processing them. 4. Restrict write access to the library file and secure any process that generates or imports it. 5. Add tests containing characters such as `<`, `>`, `&`, quotes, and sample HTML elements to verify that metadata is rendered strictly as text. 6. Ensure temporary email files retain restrictive permissions and are removed reliably with an `EXIT` trap, including when Himalaya or the script terminates unexpectedly. ]]>
