T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/cs.sh:9
- Finding
- Environment-Controlled OAuth Endpoint Can Exfiltrate Authentication Credentials<![CDATA[ ## Vulnerability Details **File Location**: `scripts/cs.sh:9`, `scripts/cs.sh:114-130`, `scripts/cs.sh:296-303`, and `scripts/cs.sh:344-351` **Vulnerability Type**: Arbitrary authentication endpoint override **Risk Level**: High ### Vulnerable Code ```bash TOKEN_URL="${CS_OAUTH_TOKEN_URL:-https://auth.openai.com/oauth/token}" ``` Authorization-code exchange: ```python body=urlencode({ 'grant_type':'authorization_code', 'client_id':pending['client_id'], 'code':code, 'code_verifier':pending['verifier'], 'redirect_uri':pending['redirect_uri'], }).encode() req=Request(token_url, data=body, method='POST', headers={ 'Content-Type':'application/x-www-form-urlencoded', 'Accept':'application/json', 'User-Agent':'cs/1.0' }) with urlopen(req, timeout=30) as resp: data=json.loads(resp.read().decode('utf-8','replace')) ``` Single-snapshot refresh: ```python resp = requests.post(token_url, data={ 'grant_type': 'refresh_token', 'refresh_token': data['refresh'], 'client_id': client_id, }, timeout=15) resp.raise_for_status() ``` Bulk snapshot refresh: ```python resp = requests.post(token_url, data={ 'grant_type': 'refresh_token', 'refresh_token': refresh, 'client_id': client_id, }, timeout=15) resp.raise_for_status() ``` ### Technical Analysis The default token endpoint is the official OpenAI OAuth endpoint. However, the `CS_OAUTH_TOKEN_URL` environment variable can replace it with an arbitrary URL without validation of the scheme, hostname, port, or path. The authorization-code flow sends the authorization code, PKCE verifier, client identifier, and redirect URI to the configured endpoint. The refresh flows send reusable refresh tokens to that endpoint. Consequently, a malicious or compromised execution environment can redirect sensitive OAuth material to an attacker-controlled service. This contradicts the documented security posture of using official OpenAI OAuth endpoints only. Endpoint config ...[truncated 1813 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `CS_OAUTH_TOKEN_URL` configurability from production code and use a fixed official endpoint: ```bash TOKEN_URL="https://auth.openai.com/oauth/token" ``` 2. If endpoint customization is required for controlled development or testing, place it behind an explicit development-only option that is disabled by default. 3. Before transmitting credentials, parse and validate the URL and require: - HTTPS - Exact hostname `auth.openai.com` - The expected port - Exact token endpoint path `/oauth/token` - No embedded username or password - No fragments or unexpected query parameters 4. Apply equivalent validation to `CS_OAUTH_AUTHORIZE_URL` so users cannot be directed to a spoofed authorization page. 5. Disable cross-origin redirects for requests carrying authorization codes, PKCE verifiers, or refresh tokens. If redirects are supported, revalidate the destination before following them and never forward sensitive request bodies to a different origin. 6. When an endpoint fails validation, terminate before reading or transmitting stored credentials. 7. Document any supported endpoint override as a dangerous testing feature and ensure cron jobs, services, and launchers sanitize authentication-related environment variables. ]]>
