T09 · Insecure Skill Coding Practices
- Location
scripts/sportslink.py:110- Finding
API Key Can Be Redirected to an Arbitrary Endpoint
- Content
View full analysis
tuple[str, str]: return ( (os.environ.get("SPORTSINC_API_URL") or "https://api.sportsinc.com/").strip().rstrip("/") + "/", (os.environ.get("SPORTSINC_API_KEY") or "").strip(), ) ``` ```python class _Client: def __init__(self, base_url: str, api_key: str, timeout: int = 30) -> None: self._base = base_url self._timeout = timeout self._s = requests.Session() self._s.headers.update({"X-API-KEY": api_key, "Accept": "application/json"}) def _request(self, method: str, path: str, *, params=None, json_body=None) -> Any: url = self._base + path.lstrip("/") last_exc = None for attempt in range(4): # resilience: retry transient failures try: resp = self._s.request( method, url, params=params, json=json_body, timeout=self._timeout, ) ``` ```python base_url, api_key = _config() if not api_key: return _fail( "config_error", "Set SPORTSINC_API_KEY (request one from mhoerner@hq.sportsinc.com).", 2, ) client = _Client(base_url, api_key) ``` ### Technical Analysis The `SPORTSINC_API_URL` environment variable controls the destination to which the authenticated `requests.Session` sends requests. The value is not parsed or validated before use. In particular, the implementation does not: - Require HTTPS. - Restrict the hostname to `api.sportsinc.com`. - Reject embedded credentials, unusual ports, or malformed URL forms. - Separate production credentials from test endpoint configuration. The `X-API-KEY` header is installed ...[truncated 1943 chars]- Remediation
View remediation
