T09 · Insecure Skill Coding Practices
- Location
scripts/check_releases.sh:36- Finding
Arbitrary Python Code Execution Through Unsafe String Interpolation
- Content
View full analysis
/dev/null) ``` ```bash python3 -c " import json with open('$STATE_FILE','r') as f: d=json.load(f) d['$repo']='$tag' with open('$STATE_FILE','w') as f: json.dump(d,f,indent=2) " ``` ### Technical Analysis The script directly interpolates shell variables into Python source passed to `python3 -c`. The values are placed inside single-quoted Python string literals without escaping or argument binding. The affected values include: - `$tag`, obtained from release metadata returned by GitHub. - `$repo`, obtained from the repository configuration. - `$STATE_FILE`, which can be supplied through an environment variable. An input containing a single quote can terminate the intended Python string literal and append arbitrary Python statements. For example, a release tag shaped like: ```text ';__import__("os").system("id");# ``` would produce Python source equivalent to: ```python d['owner/repository']='';__import__("os").system("id");#' ``` The injected `os.system` call would consequently execute on the local host. Shell quoting around the earlier `gh api` command does not prevent this issue because the injection occurs when dynamically constructing Python code. A malicious release tag is the most direct externally controlled exploitation vector. Repository maintainers or attackers who compromise release-publishing permissions can control tag names returned by the GitHub API. The environment-controlled state-file path is an additional unsafe interpolation boundary. ### Attack Path 1. A victim adds an attacker-controlled repository to `repos.txt`, or already monitors a repository whose release-publishing account is later compromised. 2. The attacker publishes a GitHub ...[truncated 1256 chars]- Remediation
View remediation
