T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/geekbi_auth.py:698
- Finding
- Authentication Data Can Be Sent to Untrusted or Insecure Origins## Vulnerability Details **File Location**: `scripts/geekbi_auth.py:698-721`; exposed through `--base-url` in `scripts/mercadolibre_mall_search.py:49-57`, `scripts/mercadolibre_mall_info.py:27-34`, and `scripts/mercadolibre_site_list.py:61-67` **Vulnerability Type**: Unrestricted authentication endpoint and transport **Risk Level**: High ### Vulnerable Code ```python def authenticated_json_request( url, base_url, timeout, *, method="GET", body=None, headers=None, ): complete_pending_login(base_url, timeout) request_headers = _api_headers() if headers: request_headers.update(headers) authorization = _authorization_header(base_url) if authorization: request_headers["token"] = authorization request = Request( url, data=body, headers=request_headers, method=method, ) try: with urlopen(request, timeout=timeout) as response: ``` The calling scripts expose the destination without validation: ```python parser.add_argument("--base-url", default=DEFAULT_BASE_URL) ... payload = authenticated_json_request( build_url(args.base_url, ENDPOINT, params), args.base_url, args.timeout ) ``` ### Technical Analysis The scripts accept an arbitrary `--base-url` and use it for API requests, authentication challenge processing, device-code polling, and bearer-token delivery. The value is not restricted to HTTPS, the expected GeekBI hostname, the default port, or an approved origin. Although authentication state is keyed by the supplied base URL, an attacker-controlled origin can initiate its own authentication challenge, supply an arbitrary `jumpUrl`, receive device-code polling data, and receive any token stored for that origin. Plain HTTP also exposes these values and query data to network interception. In addition, `urlopen` follows HTTP redirects by default. The code does not ...[truncated 2050 chars]
- Remediation
- ## Remediation Suggestions 1. Remove the production `--base-url` option and use the fixed `https://openapi.geekbi.com` origin. 2. If endpoint configurability is required for testing, gate it behind an explicit development-only mode and enforce an allowlist of exact schemes, hostnames, and ports. 3. Reject HTTP, embedded URL credentials, fragments, unexpected ports, IP-literal destinations, and malformed origins. 4. Validate every authentication `jumpUrl` against a separate allowlist of approved HTTPS login origins before presenting it to the user. 5. Disable automatic redirects for requests containing authentication data, or implement a redirect handler that only permits same-origin HTTPS redirects. 6. Verify the final response URL before processing its body. 7. Do not propagate the `token` header across redirects or origin changes. 8. Add tests covering HTTP endpoints, deceptive hostnames, user-info URL syntax, nonstandard ports, cross-origin redirects, and malicious `jumpUrl` responses.
