T09 · Insecure Skill Coding Practices
- Location
scripts/stock_utils.py:604- Finding
API Key Can Be Forwarded to an Arbitrary Network Destination
- Content
View full analysis
dict: """ POST wrapper 3: East Money-specific wrapper """ apikey = get_eastmoney_apikey(required=True) target_url = _build_eastmoney_url(endpoint) quota = None if use_daily_limit: quota = consume_eastmoney_daily_quota() LOGGER.info( "Calling East Money POST url=%s apikey=%s quota=%s payload=%s", target_url, _mask_secret(apikey), quota or "skip", _desensitize_payload(payload), ) headers = { "apikey": apikey, "X-Api-Key": apikey, } return post_json_with_retry( url=target_url, payload=payload, headers=headers, timeout=timeout, retries=retries, ) def _build_eastmoney_url(endpoint: str) -> str: target = (endpoint or "").strip() if not target: return EASTMONEY_BASE_URL.rstrip("/") if target.startswith(("http://", "https://")): return target base = EASTMONEY_BASE_URL.rstrip("/") + "/" return urljoin(base, target.lstrip("/")) ``` ### Technical Analysis The East Money base URL and endpoint paths can be supplied through environment variables. In addition, `_build_eastmoney_url()` accepts any absolut ...[truncated 2088 chars]- Remediation
View remediation
str: endpoint = str(endpoint or "").strip() if endpoint not in ALLOWED_ENDPOINTS: raise ValueError("Unsupported East Money endpoint") target = urljoin(DEFAULT_EASTMONEY_BASE_URL.rstrip("/") + "/", endpoint.lstrip("/")) parsed = urlparse(target) if ( parsed.scheme != "https" or parsed.hostname != ALLOWED_HOST or parsed.port not in (None, 443) or not parsed.path.startswith(ALLOWED_PATH_PREFIX) ): raise ValueError("Untrusted East Money destination") return target ``` ]]>
