T09 · Insecure Skill Coding Practices
- Location
scripts/gh.py:126- Finding
GitHub PAT Can Be Transmitted to an Attacker-Controlled Host
- Content
View full analysis
Vulnerability Details
File Location:
scripts/gh.py, lines 126-153
Vulnerability Type: Improper remote-host validation leading to credential disclosure
Risk Level: HighVulnerable Code
python # Check if token already in URL token_in_url = "@github.com" in remote_url if token and "github.com" in remote_url and not token_in_url: # Inject token into remote URL auth_url = remote_url.replace("https://", f"https://{token}@") use_url = True else: # Token already in URL or not needed use_url = False # Stage all changes print("📦 Staging changes...") subprocess.run(["git", "add", "-A"]) # Commit print(f"💾 Committing: {message}") result = subprocess.run(["git", "commit", "-m", message], capture_output=True, text=True) if result.returncode != 0 and "nothing to commit" in result.stdout + result.stderr: print("ℹ️ Nothing to commit") return # Push print(f"🚀 Pushing to {branch}...") if use_url: result = subprocess.run( ["git", "push", "-u", auth_url, branch], capture_output=True, text=True )Technical Analysis
The remote is classified as GitHub by testing whether the unparsed URL contains the substring
github.com. This does not verify that the URL's actual hostname isgithub.com.For example, an attacker-controlled remote such as:
text https://attacker.example/github.com/owner/repo.gitpasses the substring check. Token injection then produces:
text https://GITHUB_PAT@attacker.example/github.com/owner/repo.gitWhen
git pushprocesses that URL, it connects toattacker.exampleand can disclose the PAT as URL user information. The use of an argument array prevents shell injection, but it does not prevent this credential-forwarding vulnerability.Attack Path
- An attacker or untrusted repository configuration changes the local
originURL to a URL whose path contains ` ...[truncated 1121 chars]
- An attacker or untrusted repository configuration changes the local
- Remediation
View remediation
Remediation Suggestions
- Parse the remote with
urllib.parse.urlsplitrather than performing substring checks. - Require the normalized hostname to equal
github.comexactly. - Reject unexpected schemes, user information, ports, and malformed URLs.
- Handle SSH remotes separately and do not inject HTTP credentials into them.
- Do not embed the PAT in a URL. Use a protected Git credential helper or temporary
GIT_ASKPASSimplementation. - Clear temporary credential-related environment variables immediately after the Git operation.
- Add tests covering deceptive remotes such as:
https://attacker.example/github.com/repohttps://github.com.attacker.example/repohttps://attacker@github.com.example/repo
- Rotate any token that may already have been used with an untrusted remote.
- Parse the remote with
