T09 · Insecure Skill Coding Practices
- Location
scripts/lookup.py:438- Finding
Configurable Baike Base URL Can Exfiltrate API Keys
- Content
View full analysis
Vulnerability Details
File Location:
scripts/lookup.py:70-71, 123-126, 309-314, 438
Vulnerability Type: Credential disclosure through an unvalidated authentication endpoint override
Risk Level: HighVulnerable Code
python def build_url(base_url: str, path: str, params: dict[str, Any]) -> str: return f"{base_url.rstrip('/')}{path}?{urllib.parse.urlencode(params)}"python def get_json(url: str, key: str, timeout: int, auth_header: str) -> dict[str, Any]: request = urllib.request.Request(url, headers=build_headers(key, auth_header), method="GET") try: with urllib.request.urlopen(request, timeout=timeout) as response:python list_url = build_url( args.baike_base_url, LIST_PATH, {"lemma_title": topic, "top_k": clamp_top_k(args.top_k)}, )python parser.add_argument("--baike-base-url", default=BAIKE_BASE_URL)The authentication headers populated by
build_headers()contain the complete API key:python bearer = f"Bearer {key}" if auth_header in {"authorization", "both"}: headers["Authorization"] = bearer if auth_header in {"x-appbuilder", "both"}: headers["X-Appbuilder-Authorization"] = bearerTechnical Analysis
--baike-base-urlaccepts an arbitrary URL. The selected URL is passed toget_json(), which attaches a Baidu API key in anAuthorizationorX-Appbuilder-Authorizationheader without validating the URL scheme or destination hostname.Consequently, anyone who can influence the command-line arguments can redirect authenticated requests to an attacker-controlled server. This is particularly relevant in an agent skill because generated tool arguments may be influenced by user instructions or indirectly by untrusted retrieved content.
The key pool increases the possible exposure.
baike_get()retries the request with every configured key after failures. An attacker-controlled end ...[truncated 1356 chars]- Remediation
View remediation
Remediation Suggestions
- Remove
--baike-base-urlfrom production-facing agent commands unless endpoint substitution is strictly required. - Enforce HTTPS and an exact hostname allowlist before attaching authentication headers. For example, only permit
appbuilder.baidu.com. - Reject URLs containing user information, fragments, unexpected ports, IP literals, or non-HTTPS schemes.
- Construct the API URL from a fixed origin and fixed paths rather than concatenating an arbitrary base URL.
- If compatibility testing requires custom endpoints, require an explicit development-only flag and separate test credentials.
- Do not send production credentials to a custom endpoint under any circumstances.
- Limit retries and avoid cycling through the entire key pool when the destination has not passed validation.
- Add tests confirming that HTTP URLs, lookalike domains, subdomains, alternate ports, and attacker-controlled hosts are rejected.
- Revoke and rotate any keys that may previously have been used with an untrusted
--baike-base-url.
- Remove
