T05 · Unauthorized Access and Privilege Escalation
- Location
publish_skill.py:28- Finding
Publisher Automatically Extracts GitHub Credentials from External Credential Stores
- Content
View full analysis
Vulnerability Details
File Location:
publish_skill.py, lines 28–66
Vulnerability Type: Credential discovery beyond the minimum privileges required for publishing
Risk Level: HighVulnerable Code
python def find_github_token(): """查找GitHub token""" # 1. 环境变量 for var in ['GITHUB_TOKEN', 'GH_TOKEN', 'GITHUB_PERSONAL_ACCESS_TOKEN']: token = os.getenv(var) if token: print(f"[+] Found token in env: {var[:10]}...") return token # 2. VSCode扩展 paths = [ os.path.expandvars(r"%APPDATA%\Code\User\globalStorage\github-auth-token"), ] for path in paths: if os.path.exists(path): try: with open(path, 'r', encoding='utf-8') as f: data = json.load(f) token = data.get('token') or data.get('github_token') if token: print(f"[+] Found token in VSCode state") return token except Exception as e: print(f"[!] Error reading {path}: {e}") # 3. Git credential try: result = subprocess.run( ['git', 'credential', 'fill'], input='protocol=https\nhost=github.com\n\n', capture_output=True, text=True, encoding='utf-8', timeout=5 ) for line in result.stdout.split('\n'): if line.startswith('password='): return line[9:] except: pass return NoneTechnical Analysis
Publishing a repository legitimately requires authentication, but the script does not restrict itself to a credential explicitly supplied for the current operation. If no supported environment variable is present, it directly reads a VS Code extension storage location and invokes
git credential fillto recover a stored GitHub password or token....[truncated 1885 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove all direct reads of VS Code extension storage.
- Do not manually invoke and parse
git credential fillinside the publisher. - Accept only credentials explicitly selected for the current operation, such as:
- A fine-grained token supplied through a documented environment variable.
- GitHub CLI authentication through
gh. - SSH authentication.
- Git Credential Manager used transparently by Git.
- Require explicit confirmation of the authenticated account, repository owner, repository visibility, and destination before creating or pushing a repository.
- Recommend a fine-grained, short-lived token limited to the single target repository and only the required content permissions.
- Avoid recommending classic
reposcope unless no narrower method is available. - Do not log token values or include credentials in exception messages.
- Rotate any credential previously discovered and persisted by this implementation.
