T09 · Insecure Skill Coding Practices
- Location
scripts/fetch-trending.sh:16- Finding
Unsafe Shell Expansion May Expose the GitHub Authentication Token
- Content
View full analysis
=$SINCE&sort=stars&order=desc&per_page=$COUNT" \ $AUTH \ -H "Accept: application/vnd.github.v3+json" \ ``` ### Technical Analysis The script constructs a curl header as a plain string and later expands `$AUTH` without quotes. Shell quotation marks stored inside a variable do not become shell syntax when that variable is expanded. Consequently, a value such as: ```text -H "Authorization: token SECRET" ``` is split into multiple command-line arguments rather than passed as the intended two arguments: ```text -H "Authorization: token SECRET" ``` Curl may interpret the remaining fragments as positional URLs or options. This can result in unintended outbound requests containing token material and may expose the token through URL handling, DNS resolution attempts, proxy logs, curl diagnostics, or other network telemetry. It also causes the authenticated request to be malformed and likely prevents authentication from working as documented. Because `GH_TOKEN` is incorporated into an unquoted argument string, a specially crafted value containing whitespace and curl options could also alter curl's command-line behavior. This requires an attacker to influence the process environment, but the script should still treat authentication material as opaque data rather than executable command-line structure. The request to GitHub's official API is necessary for the declared trending-repository functionality, and optional authenticated access is legitimate. However, creating potential unintended destinations is not necessary and violates least-privilege network behavior. ### ...[truncated 1421 chars]- Remediation
View remediation
=$SINCE&sort=stars&order=desc&per_page=$COUNT" \ -H "Accept: application/vnd.github.v3+json" \ -H "User-Agent: openclaw-trending" \ | jq -r '.items | to_entries[] | "\(.key+1). \(.value.full_name) ⭐ \(.value.stargazers_count) 🍴 \(.value.forks_count) 🔤 \(.value.language // "N/A") 📝 \(.value.description // "No description" | .[0:120]) 🔗 https://github.com/\(.value.full_name) "' ``` Additional hardening measures: - Use a minimally scoped and short-lived GitHub token. - Keep the API endpoint fixed to `https://api.github.com` and avoid allowing environment variables to override it. - Do not print authentication values in errors, debug traces, or command logs. - Avoid running the script with `set -x`, which could expose header arguments. - Add a regression test that captures curl's argument vector and verifies that the complete authorization header is passed as exactly one argument after `-H`. - Consider using curl's configuration or header-file mechanisms with appropriately protected temporary storage only if process argument visibility is a concern. ]]>
