T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/ingest.py:976
- Finding
- Raw GitHub Access Token Disclosed to a Third-Party Service During Automatic Setup<![CDATA[ ## Vulnerability Details **File Location**: `scripts/ingest.py:976-1027` and `scripts/ingest.py:1105-1114` **Vulnerability Type**: Credential disclosure and excessive privilege acquisition **Risk Level**: Critical ### Vulnerable Code ```python def _get_gh_token() -> str | None: """Get the current GitHub auth token from gh CLI.""" try: result = subprocess.run( ["gh", "auth", "token"], capture_output=True, text=True, timeout=5, ) token = result.stdout.strip() if token and result.returncode == 0: return token except (FileNotFoundError, subprocess.TimeoutExpired, OSError): pass return None CLI_AUTH_PATH = "/api/auth/cli" def run_setup(endpoint: str, verbose: bool = False) -> str | None: """ Auto-setup: exchange a GitHub token for a ClawRank API token. Returns the raw cr_live_ token on success, or None on failure. """ print("▸ ClawRank auto-setup") print() # Step 1: Get GitHub token from gh CLI print(" [1/3] Getting GitHub identity from gh CLI...") gh_token = _get_gh_token() if not gh_token: print(" ✗ Could not get GitHub token. Make sure gh CLI is installed and authenticated.", file=sys.stderr) print(" Run: gh auth login", file=sys.stderr) return None if verbose: print(f" Got GitHub token ({gh_token[:8]}...)") # Step 2: Exchange for ClawRank API token print(" [2/3] Registering with ClawRank...") url = f"{endpoint}{CLI_AUTH_PATH}" body = json.dumps({"githubToken": gh_token, "label": "auto-setup"}).encode("utf-8") req = urllib.request.Request( url, data=body, headers={"Content-Type": "application/json"}, method="POST", ) try: with urllib.request.urlopen(req, timeout=30) as resp: data = json.loads(resp.read().decode("utf-8")) ``` Automatic invocation occurs when the ClawRank token is absent: ``` ...[truncated 2956 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `_get_gh_token()` and never invoke `gh auth token`. 2. Never send an existing GitHub CLI credential to ClawRank or any other service. 3. Implement a standard GitHub OAuth web or device authorization flow: - Register a dedicated OAuth application. - Request only the minimum identity scopes required. - Display the requested scopes and obtain explicit user consent. - Exchange authorization codes directly through the documented OAuth protocol. 4. If only account identity is needed, use a narrowly scoped identity assertion rather than repository-authorized credentials. 5. Make setup an explicit action instead of automatically initiating credential-bearing authentication when a token is absent. 6. Clearly disclose the recipient, data fields, purposes, retention period, and requested permissions before authorization. 7. Revoke any GitHub credentials previously transmitted through this mechanism and instruct affected users to rotate them. 8. Store the resulting ClawRank token in an operating-system credential store or a file created with owner-only permissions rather than placing it in a general plaintext configuration file. ]]>
