T09 · Insecure Skill Coding Practices
- Location
lib/image_video.py:20- Finding
Bearer API Key Can Be Forwarded to an Arbitrary Network Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
lib/image_video.py:20-56
Additional Request Sinks:lib/image_video.py:100-116
Vulnerability Type: Unvalidated credential destination
Risk Level: MediumVulnerable Code
python def __init__( self, api_key: Optional[str] = None, base_url: str = "https://open.bigmodel.cn/api", timeout: int = 60, ): self.api_key = api_key or os.environ.get("BIGMODEL_API_KEY") if not self.api_key: raise ValueError("需要设置 BIGMODEL_API_KEY 环境变量") self.base_url = base_url self.timeout = timeout self._headers = { "Authorization": f"Bearer {self.api_key}", "Content-Type": "application/json", } def generate_image( self, prompt: str, model: str = "cogview-3-flash", quality: str = "standard", size: str = "1024x1024", watermark_enabled: bool = True, ) -> dict: """生成单张图片""" resp = requests.post( f"{self.base_url}/paas/v4/images/generations", headers=self._headers, json={ "model": model, "prompt": prompt, "quality": quality, "size": size, "watermark_enabled": watermark_enabled, }, timeout=self.timeout, ) resp.raise_for_status() return resp.json()The same unvalidated
self.base_urland authorization headers are used by the video-generation and task-status requests:python resp = requests.post( f"{self.base_url}/paas/v4/videos/generations", headers=self._headers, json=payload, timeout=self.timeout, ) resp = requests.get( f"{self.base_url}/paas/v4/async-result/{task_id}", headers=self._headers, timeout=30, )Technical Analysis
BigModelClientpermits callers to replace the documented BigModel API endpoint with an arbitrarybase_url. The value is not res ...[truncated 2072 chars]- Remediation
View remediation
Remediation Suggestions
- Remove the configurable
base_urlparameter if custom endpoints are not required. - If endpoint customization is necessary, parse the URL and enforce:
- The
httpsscheme. - An explicit hostname allowlist, such as
open.bigmodel.cn. - The expected port and API path.
- Rejection of embedded credentials, fragments, and malformed hostnames.
- The
- Keep authentication headers scoped to the approved origin rather than storing them in a reusable header dictionary for arbitrary destinations.
- Disable automatic redirects for authenticated requests or validate every redirect target before following it.
- Separate custom or test endpoints from production credentials. Require an explicitly supplied test credential for non-production hosts.
- Add tests confirming that HTTP URLs, look-alike domains, IP addresses, and unapproved redirect targets are rejected.
- Remove the configurable
