T09 · Insecure Skill Coding Practices
- Location
scripts/weixia.py:18- Finding
Configurable API Endpoint Can Exfiltrate the Stored API Key
- Content
View full analysis
Vulnerability Details
File Location:
scripts/weixia.py:18, 42-55;scripts/weixia.sh:11, 106-108
Vulnerability Type: Unvalidated credential destination
Risk Level: HighVulnerable Code
python # API address API_BASE = os.getenv("WEIXIA_API_BASE", "https://api.weixia.chat") def get_api_key() -> Optional[str]: """Get the saved API key.""" if API_KEY_FILE.exists(): return API_KEY_FILE.read_text().strip() return None def _headers() -> dict: """Build request headers.""" api_key = get_api_key() if api_key: return {"Authorization": api_key, "Content-Type": "application/json"} return {"Content-Type": "application/json"}bash API_BASE="${WEIXIA_API_BASE:-https://api.weixia.chat}" export WEIXIA_API_BASE "$PYTHON" "$PYTHON_SCRIPT" "$@"Technical Analysis
The remote service origin is accepted directly from the inherited
WEIXIA_API_BASEenvironment variable without validating its scheme, hostname, port, or embedded credentials. Authenticated operations use_headers(), which reads the API key from~/.weixia/.api_keyand adds it to theAuthorizationheader.Consequently, a process or execution environment that controls this variable can redirect authenticated requests to an attacker-controlled server. The implementation also does not require HTTPS, so it can be directed to a plaintext HTTP endpoint.
Attack Path
- An attacker influences the Skill's environment, wrapper, shell profile, CI configuration, or invocation and sets
WEIXIA_API_BASEto an attacker-controlled URL. - The user runs an authenticated operation such as
me,balance,transfer, orwithdraw. _headers()reads the stored API key from~/.weixia/.api_key.- The client sends the API key in the
Authorizationheader to the configured endpoint. - The attacker captures the key and submits authenticated requests to the legitimate W ...[truncated 591 chars]
- An attacker influences the Skill's environment, wrapper, shell profile, CI configuration, or invocation and sets
- Remediation
View remediation
Remediation Suggestions
- Require
httpsfor every endpoint that may receive credentials. - Parse the URL and reject embedded credentials, fragments, unexpected ports, malformed hostnames, and non-HTTPS schemes.
- Restrict credential-bearing requests to an explicit allowlist such as
api.weixia.chat. - If custom endpoints are required for development, require explicit user approval before transmitting a stored key to a non-default origin.
- Maintain credentials per origin rather than applying one stored key to every configured endpoint.
- Consider ignoring inherited endpoint overrides for wallet and account-management commands unless a secure configuration file explicitly enables them.
- Add automated tests confirming that credentials are never sent to HTTP or unapproved origins.
- Require
