T09 · Insecure Skill Coding Practices
- Location
scripts/datayes_api.py:40- Finding
Bearer Token Can Be Forwarded to an Untrusted Host Through HTTP Redirects
- Content
View full analysis
Any: body = None headers = { "Authorization": f"Bearer {token}", "Accept": "application/json", } if payload is not None: body = json.dumps(payload).encode("utf-8") headers["Content-Type"] = "application/json" request = urllib.request.Request(url=url, data=body, headers=headers, method=method) try: with urllib.request.urlopen(request, timeout=TIMEOUT) as response: ``` The initial business API URL is validated as follows: ```python def _validate_http_url(http_url: str) -> str: parsed = urllib.parse.urlparse(http_url) if parsed.scheme != "https": raise DatayesError(f"Resolved httpUrl must use https: {http_url}") if not parsed.netloc: raise DatayesError(f"Resolved httpUrl is missing a host: {http_url}") host = (parsed.hostname or "").lower() if host not in ALLOWED_HTTP_HOSTS: allowed_hosts = ", ".join(sorted(ALLOWED_HTTP_HOSTS)) raise DatayesError( f"Resolved httpUrl host {host or ''} is not trusted. Allowed hosts: {allowed_hosts}" ) return http_url ``` ### Technical Analysis The Skill needs authenticated network access to provide its declared Datayes stock-data functionality. Passing `DATAYES_TOKEN` to the fixed Datayes specification endpoint and validated Datayes business endpoints is therefore functionally justified and does not, by itself, exceed minimum required privileges. However, `_validate_http_url()` validates only the initial URL. The subsequent call to `urllib.request.urlopen()` uses Python's default redirect handling. The request already contains the sensitive `Au ...[truncated 2134 chars]- Remediation
View remediation
