T09 · Insecure Skill Coding Practices
- Location
scripts/provider_probe.py:18- Finding
API Credentials May Be Disclosed Through Plaintext Transport or Unsafe Redirects
- Content
View full analysis
Vulnerability Details
File Location:
scripts/provider_probe.py, lines 18–40
Vulnerability Type: Missing transport and destination validation for sensitive credentials
Risk Level: Highpython def http_call(base_url, api_key, endpoint_kind, model, prompt, timeout=25): headers = { 'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0', } base = base_url.rstrip('/') if endpoint_kind == 'responses': url = base + '/responses' body = {'model': model, 'input': prompt, 'max_output_tokens': 128} elif endpoint_kind == 'chat': url = base + '/chat/completions' body = {'model': model, 'messages': [{'role': 'user', 'content': prompt}], 'max_tokens': 128, 'temperature': 0} elif endpoint_kind == 'models': url = base + '/models' body = None else: raise ValueError(endpoint_kind) data = None if body is None else json.dumps(body).encode() req = urllib.request.Request(url, data=data, headers=headers, method='GET' if body is None else 'POST') started = time.time() try: with urllib.request.urlopen(req, timeout=timeout) as r:Technical Analysis
The function unconditionally places the supplied API key in an HTTP
Authorizationheader, but it does not parse or validatebase_urlbefore transmitting the credential. In particular, it does not require HTTPS, reject embedded URL credentials, restrict destination ports, or enforce a same-origin redirect policy.A provider URL using
http://therefore transmits the bearer credential without TLS protection. In addition,urllib.request.urlopenfollows supported redirects by default. The implementation does not independently validate each redirect target or explicitly remove authorization information when the destination origin changes. A malicious or compromised provider ma ...[truncated 1724 chars]- Remediation
View remediation
Remediation Suggestions
- Parse
base_urlwithurllib.parse.urlsplitbefore constructing any request. - Require the URL scheme to be exactly
https. - Reject URLs containing user information, fragments, malformed hosts, or unexpected schemes.
- Consider restricting ports to an explicit allowlist, such as 443, unless the user deliberately authorizes another TLS port.
- Disable automatic redirects for authenticated requests, or implement a custom redirect handler.
- If redirects are required, permit only HTTPS redirects that preserve the exact original scheme, hostname, and effective port.
- Strip the
Authorizationheader before any cross-origin redirect. - Validate every redirect destination before issuing the redirected request.
- Add tests covering HTTP URLs, HTTPS-to-HTTP downgrade redirects, cross-host redirects, and same-origin redirects.
- Display a clear error rather than silently attempting a request when URL validation fails.
- Parse
