T09 · Insecure Skill Coding Practices
- Location
scripts/bimiyun_search.py:34- Finding
Unrestricted API endpoint override can disclose credentials and search queries
- Content
View full analysis
Vulnerability Details
File Location:
scripts/bimiyun_search.py, lines 34-53 and 62-101
Vulnerability Type: Arbitrary credential-bearing network destination
Risk Level: HighVulnerable Code
python def load_endpoint() -> str: """Load the Bimiyun Search API endpoint.""" endpoint = os.environ.get("BIMIYUN_ENDPOINT") if endpoint: return endpoint.strip() if os.path.exists(".env"): try: with open(".env", "r", encoding="utf-8", errors="ignore") as f: txt = f.read() m = re.search(r"^\s*BIMIYUN_ENDPOINT\s*=\s*(.+?)\s*$", txt, re.M) if m: return m.group(1).strip().strip('"').strip("'") except Exception: pass return "https://search.bimiyun.com/api/web"python def __init__(self, api_key: Optional[str] = None, endpoint: Optional[str] = None): self.api_key = api_key or load_key() self.endpoint = endpoint or load_endpoint()python req = urllib.request.Request( self.endpoint, data=data, headers={ "Content-Type": "application/json", "Accept": "application/json", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "X-Api-Key": self.api_key, }, method="POST", ) with urllib.request.urlopen(req, timeout=30) as resp: body = resp.read().decode("utf-8", errors="replace")Technical Analysis
The request destination can be supplied through
BIMIYUN_ENDPOINT, a local.envfile, or the publicBimiyunSearchconstructor. The destination is used without validating its scheme, hostname, port, or ownership.The same request includes the sensitive API key in the
X-Api-Keyheader and the user's search query in the JSON body. Consequently, anyone who can influence the endpoint configuration ...[truncated 1632 chars]- Remediation
View remediation
Remediation Suggestions
- Remove endpoint configurability unless it is operationally required, and use the fixed official endpoint.
- If endpoint customization is required, parse the URL and enforce:
- The
httpsscheme. - An explicit allowlist containing
search.bimiyun.com. - The expected port.
- No embedded user information, fragments, IP literals, or deceptive subdomains.
- The
- Reject redirects to a different origin and ensure the API-key header is never forwarded across host boundaries.
- Do not silently accept endpoint configuration from an arbitrary working-directory
.envfile. - Separate development/test endpoint support from production builds and require explicit opt-in without production credentials.
- Use scoped, revocable API keys and rotate any credential that may have been transmitted to an untrusted endpoint.
