T09 · Insecure Skill Coding Practices
- Location
scripts/search.mjs:43- Finding
API Credential and Search Query Exposure Through an Unrestricted Endpoint Override
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search.mjs, lines 43 and 70–76
Vulnerability Type: Unvalidated destination for sensitive outbound data
Risk Level: MediumVulnerable Code
js const baseUrl = process.env.ZAI_BASE_URL ?? "https://api.z.ai/api/coding/paas/v4";js const resp = await fetch(`${baseUrl}/chat/completions`, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${apiKey}`, }, body: JSON.stringify(body), });Technical Analysis
The script permits the
ZAI_BASE_URLenvironment variable to replace the official Z.AI API endpoint without validating its scheme, hostname, port, or path. It subsequently sends both the API credential in theAuthorizationheader and the user-provided search query in the request body to that destination.Supporting a completely arbitrary endpoint is not documented as part of the Skill's search functionality and exceeds the minimum privileges required to communicate with the official Z.AI service. The implementation also accepts an
http://URL, potentially transmitting the bearer credential and query without transport encryption.An attacker must be able to influence the process environment or deployment configuration. This is not evidence of intentional exfiltration: when no override is supplied, the script uses the expected official HTTPS endpoint.
Attack Path
- An attacker gains the ability to set or alter environment variables for the process executing the Skill, such as through an unsafe launcher, compromised deployment configuration, or inherited shell environment.
- The attacker sets
ZAI_BASE_URLto an attacker-controlled endpoint, for examplehttps://attacker.exampleor an unencryptedhttp://endpoint. - A user invokes
scripts/search.mjswith a search query. - The script reads the legitimate API key from
ZAI_API_KEYorZ_AI_API_KEY. - The script sends a POST request to the attacker-controlle ...[truncated 869 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove the undocumented
ZAI_BASE_URLoverride and use a fixed official endpoint where custom API hosts are not required:js const baseUrl = "https://api.z.ai/api/coding/paas/v4"; -
If endpoint customization is a legitimate requirement, parse the value with
URLand enforce:- The
https:scheme. - An explicit allowlist of trusted hostnames.
- An expected port and path prefix.
- Rejection of embedded credentials and unexpected URL components.
- The
-
Do not forward the production Z.AI credential to arbitrary custom endpoints. Require a separate, explicitly configured credential for non-official endpoints.
-
Fail closed when URL validation fails, before constructing or sending the request.
-
Document all outbound data, including that search queries and authorization credentials are sent to Z.AI.
-
Avoid including full upstream response bodies in error messages because they may contain sensitive service details. Return a bounded and sanitized diagnostic instead.
-
Add automated tests confirming that plaintext HTTP, unknown hosts, malformed URLs, and redirect-based attempts cannot receive the bearer token.
-
