T09 · Insecure Skill Coding Practices
- Location
- scripts/fetch_api_overview.py:37
- Finding
- TLS Certificate Verification Can Be Disabled in API Overview Retrieval<![CDATA[ ## Vulnerability Details **File Location**: `scripts/fetch_api_overview.py:37-59` **Vulnerability Type**: Improper TLS certificate validation **Risk Level**: Medium ### Vulnerable Code ```python def fetch_page(url: str, timeout: int) -> str: """Fetch page HTML. Tries urllib first, falls back to curl on SSL errors.""" import ssl import subprocess headers = { "User-Agent": ( "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " "AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/131.0.0.0 Safari/537.36" ), } # Try with default SSL context first for ctx in [None, ssl.create_default_context(), ssl._create_unverified_context()]: try: req = urllib.request.Request(url, headers=headers) kwargs: dict = {"timeout": timeout} if ctx is not None: kwargs["context"] = ctx with urllib.request.urlopen(req, **kwargs) as resp: return resp.read().decode("utf-8") except (urllib.error.URLError, ssl.SSLError): continue ``` The script also accepts an unrestricted custom endpoint: ```python parser.add_argument("--url", default=DEFAULT_URL, help="Help doc URL") ``` ### Technical Analysis The request sequence eventually uses `ssl._create_unverified_context()`. This disables certificate-chain and server-identity verification after verified HTTPS attempts fail. Consequently, a TLS failure does not cause the operation to fail closed. The downloaded page is parsed into API names and descriptions and saved for subsequent Agent use. Although the script does not directly execute downloaded code or transmit credentials, forged documentation can influence later authenticated cloud operations. The unrestricted `--url` argument also permits retrieval from arbitrary schemes and hosts without an Alibaba Cloud hostname allowlist. ### Attack Path 1. An Agent or user runs `scripts/fetch_api_overview.py ...[truncated 908 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `ssl._create_unverified_context()` and fail closed when certificate verification fails. 2. If private certificate authorities must be supported, accept an explicit CA bundle and construct a verified context with `ssl.create_default_context(cafile=...)`. 3. Require HTTPS for `--url`. 4. Allowlist expected hosts such as `help.aliyun.com`, unless arbitrary endpoints are an explicitly required feature. 5. Validate redirects so an approved initial URL cannot redirect to an untrusted host or non-HTTPS scheme. 6. Apply response-size limits and validate the expected document structure before writing generated output. 7. Emit a clear error explaining how to configure a trusted CA instead of silently weakening TLS. ]]>
