T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/excel_api_client.py:520
- Finding
- API Key Disclosure Through Unrestricted Backend URL Override<![CDATA[ ## Vulnerability Details **File Location**: `scripts/excel_api_client.py`, lines 140-171 and 520-521 **Vulnerability Type**: Credential disclosure through an attacker-controlled network destination **Risk Level**: High ### Vulnerable Code ```python self.base_url = base_url.rstrip("/") # Get api key: explicit > env var if api_key is not None: self.api_key = api_key else: self.api_key = _get_api_key_auto() self.timeout = timeout if not self.api_key: raise ValueError("SKYWORK_API_KEY is required (set env or pass api_key=)") self._headers = {"Authorization": f"Bearer {self.api_key}"} ``` ```python def _build_request( self, url: str, method: str = "GET", headers: Optional[dict] = None, data: Optional[bytes] = None ) -> urllib.request.Request: """Build a urllib request with merged headers.""" request_headers = {**self._headers} if headers: request_headers.update(headers) return urllib.request.Request(url=url, data=data, headers=request_headers, method=method) def _urlopen( self, request: urllib.request.Request, timeout: Optional[int] = None ): """Open a URL request with configured timeout.""" return urllib.request.urlopen(request, timeout=timeout or self.timeout) ``` ```python parser.add_argument("--base-url", default=SKYWORK_GATEWAY_URL, help="Backend service URL") ``` ### Technical Analysis The client accepts an unrestricted `--base-url` value while `_build_request()` automatically attaches the Skywork Bearer credential to every request. There is no scheme validation, hostname allowlist, origin validation, or redirect-target validation before transmitting the credential. Although sending the API key to the declared Skywork service is necessary for the Skill, allowing the same credential to be sent to an arbitrary caller-selected destination exceeds minimum privilege. The initial health-check request is sufficient to disclose the credential; successful ...[truncated 1053 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the `--base-url` option from production builds unless custom backends are an explicit requirement. 2. Enforce an allowlist of exact HTTPS origins, such as `https://api-tools.skywork.ai`, before constructing any authenticated request. 3. Parse URLs with `urllib.parse.urlsplit()` and validate the scheme, normalized hostname, and effective port. 4. Do not attach `Authorization` by default to every request. Add it only after confirming that the request destination matches an approved origin. 5. Disable automatic redirects for authenticated requests, or validate every redirect destination and strip authorization headers whenever the origin changes. 6. Reject URLs containing user information, non-HTTPS schemes, unexpected ports, or ambiguous hostname encodings. 7. Add tests proving that credentials are not sent to unapproved hosts or cross-origin redirect targets. ]]>
