Back to skill

Security audit

zai-search

Security checks for vulnerabilities and agentic risk

Overview

This search skill mostly does what it says, but it can send the user's Z.AI API key and query to an arbitrary endpoint through an undocumented environment override.

Review before installing. Use only in an environment where ZAI_BASE_URL is unset or explicitly trusted, because a modified value can redirect your Z.AI API key and search query away from the official Z.AI endpoint. The skill does not show malicious behavior or persistence, but the endpoint override should be fixed or tightly controlled.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Warning
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: Medium

Vulnerable 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_URL environment 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 the Authorization header 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

  1. 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.
  2. The attacker sets ZAI_BASE_URL to an attacker-controlled endpoint, for example https://attacker.example or an unencrypted http:// endpoint.
  3. A user invokes scripts/search.mjs with a search query.
  4. The script reads the legitimate API key from ZAI_API_KEY or Z_AI_API_KEY.
  5. The script sends a POST request to the attacker-controlle ...[truncated 869 chars]
Remediation
View remediation

Remediation Suggestions

  1. Remove the undocumented ZAI_BASE_URL override and use a fixed official endpoint where custom API hosts are not required:

    js
    const baseUrl = "https://api.z.ai/api/coding/paas/v4";
    
  2. If endpoint customization is a legitimate requirement, parse the value with URL and enforce:

    • The https: scheme.
    • An explicit allowlist of trusted hostnames.
    • An expected port and path prefix.
    • Rejection of embedded credentials and unexpected URL components.
  3. Do not forward the production Z.AI credential to arbitrary custom endpoints. Require a separate, explicitly configured credential for non-official endpoints.

  4. Fail closed when URL validation fails, before constructing or sending the request.

  5. Document all outbound data, including that search queries and authorization credentials are sent to Z.AI.

  6. Avoid including full upstream response bodies in error messages because they may contain sensitive service details. Return a bounded and sanitized diagnostic instead.

  7. Add automated tests confirming that plaintext HTTP, unknown hosts, malformed URLs, and redirect-based attempts cannot receive the bearer token.

Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (2)

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
89% confidence
Finding

The skill requires environment access to ZAI_API_KEY and performs networked operations, but it does not explicitly declare a tool scope such as permissions or allowed-tools. This creates a transparency and policy-enforcement gap: hosts or reviewers cannot easily verify that the skill is expected to access secrets and the network, increasing the risk of overbroad execution or abuse if the skill is modified or misused.

Content

No source excerpt is available for this finding.

External Transmission

Medium
Category
Data Exfiltration
Confidence
50% confidence
Finding

Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.

Content

Scanner excerpt · scripts/search.mjs (reported line 48)May include surrounding context.

js
process.exit(1);
}

const baseUrl = process.env.ZAI_BASE_URL ?? "https://api.z.ai/api/coding/paas/v4";
const model = "glm-4.5-flash";

// ─── Build request ─────────────────────────────────────────────