T05 · Unauthorized Access and Privilege Escalation
Warning
- Location
- scripts/set_github_secret.py:31
- Finding
- Automatic Access to the User's Plaintext GitHub Credential Store## Vulnerability Details **File Location**: `scripts/set_github_secret.py`, lines 31-40 **Vulnerability Type**: Excessive credential access and insecure credential discovery **Risk Level**: Medium ### Vulnerable Code ```python def get_token(): tok = os.environ.get("GITHUB_TOKEN", "") if tok: return tok cred = os.path.join(os.path.expanduser("~"), ".git-credentials") if os.path.exists(cred): m = re.search(r"(gh[oUp]_[A-Za-z0-9]+)", open(cred, encoding="utf-8", errors="replace").read()) if m: return m.group(1) sys.exit("Cannot obtain a GitHub token") ``` Related instructions also explicitly recommend extracting a token from the credential file in `SKILL.md`, lines 77-80: ```bash TOKEN=$(grep -o "gho_[A-Za-z0-9]*" ~/.git-credentials) curl --noproxy '*' -H "Authorization: Bearer $TOKEN" \ https://api.github.com/repos/<owner>/<repo>/actions/{secrets,variables} ``` ### Technical Analysis When `GITHUB_TOKEN` is absent, the helper automatically opens and reads the user's entire `~/.git-credentials` file. That file can contain plaintext credentials for multiple repositories, accounts, and Git hosting services. The regular expression selects the first token matching one of several GitHub token prefixes without verifying the credential's host, account, repository scope, or intended use. Reading a broad credential store is not required to set a GitHub Actions secret. The tool could instead require an explicitly supplied environment variable, standard input, or Git's credential-helper interface. The current behavior crosses a least-privilege boundary by accessing credentials unrelated to the requested operation. The token is subsequently placed in the `Authorization` header for requests to the fixed `https://api.github.com` endpoint. The reviewed implementation does not send the token to an arbitrary host and does not print ...[truncated 1181 chars]
- Remediation
- ## Remediation Suggestions 1. Remove the automatic fallback that opens `~/.git-credentials`. 2. Require an explicitly supplied `GITHUB_TOKEN`, a secure standard-input option, or a recognized OS secret store. 3. If Git credential integration is necessary, use the Git credential-helper protocol and request credentials specifically for `github.com` rather than parsing the complete file. 4. Require fine-grained, repository-scoped tokens with only the Actions secrets or variables permissions needed for the requested operation. 5. Validate `--repo` against a strict `owner/repository` format before constructing an API path. 6. Document token requirements and fail closed when an explicit credential is unavailable.
