T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/geekbi_auth.py:698
- Finding
- Arbitrary API Origin Can Receive Authentication Material and Bearer Tokens## Vulnerability Details **File Location**: `scripts/geekbi_auth.py:698-721`; caller-controlled input originates at `scripts/mercadolibre_goods_search.py:63-70` and equivalent `--base-url` arguments in the other query scripts. **Vulnerability Type**: Unrestricted authentication destination and insecure transport **Risk Level**: High ### Vulnerable Code ```python # scripts/mercadolibre_goods_search.py:63-70 parser.add_argument("--base-url", default=DEFAULT_BASE_URL) parser.add_argument("--param", action="append", default=[], help="Query parameters") parser.add_argument("--timeout", type=float, default=30) args = parser.parse_args() try: params = parse_params(args.param) payload = authenticated_json_request( build_url(args.base_url, ENDPOINT, params), args.base_url, args.timeout ) ``` ```python # scripts/geekbi_auth.py:698-721 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: response_payload = _read_json_response(response) ``` ```python # scripts/geekbi_auth.py:564-578 def complete_pending_login(base_url, timeout): payload = _load_state() server_key = _server_key(base_url) server = payload["servers"].get(server_key) if not isinstance(server, dict): return False now = int(time.time()) changed = _clear_expired(server, now) pending = server.get("pending") if not is ...[truncated 2304 chars]
- Remediation
- ## Remediation Suggestions - Remove `--base-url` from production-facing commands unless custom endpoints are an explicit requirement. - Parse URLs with `urllib.parse.urlsplit` and require an exact allowlisted HTTPS origin, such as `https://openapi.geekbi.com`. - Reject non-HTTPS schemes, user information, fragments, unexpected ports, IP literals, and unapproved hostnames. - Normalize hosts before using them as token-store keys. - Before attaching authentication headers, verify that the request URL and authentication base URL have exactly the same scheme, hostname, and effective port. - Disable redirects for authenticated requests or validate every redirect target before resending any sensitive request. - Never forward the `token` header across an origin change. - If development endpoints are needed, place them behind an explicit opt-in configuration with a separate token store and clear security warnings.
