Back to skill

Security audit

Weixin

Security checks for vulnerabilities and agentic risk

Overview

This WeChat API skill is coherent and mostly disclosed, but it caches a powerful access token in an unsafe predictable temp file and includes broad posting/API authority.

Review before installing if you use this on a shared machine or with production WeChat credentials. Prefer a private cache directory or disable disk caching, protect WX_SECRET, and require explicit user approval before publishing content or sending template/group messages through the generic API caller.

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/wxoa.py:57
Finding

Insecure Storage of WeChat Access Token in a Predictable Temporary File

Content
View full analysis
str: appid = os.environ.get("WX_APPID") or die("未设置 WX_APPID") secret = os.environ.get("WX_SECRET") or die("未设置 WX_SECRET") cache_file = CACHE % appid try: c = json.load(open(cache_file)) if c["expire_at"] > time.time(): return c["token"] except Exception: pass q = urllib.parse.urlencode( {"grant_type": "client_credential", "appid": appid, "secret": secret}) r = http(f"{API}/cgi-bin/token?{q}") if "access_token" not in r: die(f"取 token 失败: {r} (40164=IP不在白名单, 40125=secret错误)") json.dump({"token": r["access_token"], "expire_at": time.time() + 7000}, open(cache_file, "w")) return r["access_token"] ``` ### Technical Analysis The script stores a privileged WeChat access token in the system temporary directory using a filename derived from the AppID: ```text /tmp/wxoa_token_.json ``` An AppID is generally not secret, making the cache path predictable. The file is opened using ordinary `open()` calls without: - Explicitly setting restrictive permissions such as `0600`. - Verifying that the file is owned by the current user. - Rejecting symbolic links. - Using exclusive file creation. - Writing to a secure temporary file followed by atomic replacement. - Placing the cache inside a user-private directory. The permissions assigned during creation depend on the process umask. With a common `022` umask, the resulting file may be readable by other local users. The cached access token authorizes operations against the associated WeChat account until it expires or ...[truncated 2747 chars]
Remediation
View remediation
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Taint TrackingDirect Taint Flow, Variable-Mediated Taint Flow, Credential Exfiltration Chain
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (4)

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
95% confidence
Finding

The skill describes executable capabilities that use environment secrets, perform network requests to external APIs, and write a local token cache file, but it does not declare any explicit tool scope or permission boundaries. This can cause an agent platform to expose broader capabilities than users or policy expect, increasing the risk of unauthorized API calls, secret misuse, or unintended file writes during automated execution.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The user-facing docstring, command descriptions, and error/help text are entirely in Chinese, which imposes a specific language on users. There is no opt-in, alternate language option, or explanation that the tool is intentionally limited to a Chinese-speaking or region-specific audience.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The script stores the WeChat access token in a predictable file under the system temporary directory for about 7000 seconds, without setting restrictive permissions or warning the user. On multi-user systems or insecure temp-directory setups, other local users or processes may read or tamper with the cached token, enabling unauthorized API calls as the公众号/小程序.

Content

No source excerpt is available for this finding.

Tainted flow: 'cache_file' from os.environ.get (line 56, credential/environment) → open (file write)

Medium
Category
Data Flow
Confidence
65% confidence
Finding

Data from a source is assigned to a variable that is later passed to a sink, creating a variable-mediated taint flow.

Content

Scanner excerpt · scripts/wxoa.py (reported line 69)May include surrounding context.

python
if "access_token" not in r:
        die(f"取 token 失败: {r} (40164=IP不在白名单, 40125=secret错误)")
    json.dump({"token": r["access_token"],
               "expire_at": time.time() + 7000}, open(cache_file, "w"))
    return r["access_token"]

Static analysis

No suspicious patterns detected.