T09 · Insecure Skill Coding Practices
- Location
scripts/wechat_api.py:103- Finding
Access Token Cache Created Without Restrictive File Permissions
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This WeChat publishing helper is mostly purpose-aligned, but it handles powerful account credentials in ways that could expose them through files or logs.
Review before installing on shared machines or logged agent environments. Use it only with a WeChat account you intend the agent to access, protect config.env with owner-only permissions, avoid running the token command where output is logged, and verify every file path and draft JSON before upload because content is sent to WeChat servers.
scripts/wechat_api.py:103Access Token Cache Created Without Restrictive File Permissions
scripts/wechat_api.py:295Bearer Access Token Disclosed Through Standard Output
config.env.example.txt:1Credential Setup Can Produce Unprotected or Accidentally Committed Secrets
Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.
req.add_header("Content-Type", "application/json; charset=utf-8")
try:
with urllib.request.urlopen(req, timeout=30) as resp:
result = json.loads(resp.read().decode())
except urllib.error.HTTPError as e:
body = e.read().decode()
Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.
req.add_header("Content-Type", "application/json; charset=utf-8")
try:
with urllib.request.urlopen(req, timeout=30) as resp:
result = json.loads(resp.read().decode())
except urllib.error.HTTPError as e:
body = e.read().decode()
Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.
req = urllib.request.Request(url, data=b"".join(body_bytes), method="POST")
req.add_header("Content-Type", f"multipart/form-data; boundary={boundary}")
with urllib.request.urlopen(req, timeout=60) as resp:
result = json.loads(resp.read().decode())
if result.get("errcode") == 0 or "media_id" in result:
Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.
req = urllib.request.Request(url, data=b"".join(body_bytes), method="POST")
req.add_header("Content-Type", f"multipart/form-data; boundary={boundary}")
with urllib.request.urlopen(req, timeout=60) as resp:
result = json.loads(resp.read().decode())
if result.get("errcode") == 0 or "media_id" in result:
Tool parameters are crafted to achieve unintended or unsafe behavior. Parameter abuse can bypass intended safety checks (e.g. shell=True, --force, dangerous glob patterns).
Token 过期,清除缓存后重试:
rm ~/.hermes/skills/wechat-api-lite/scripts/.token_cache
图片用 url 还是 media_id?
Tool parameters are crafted to achieve unintended or unsafe behavior. Parameter abuse can bypass intended safety checks (e.g. shell=True, --force, dangerous glob patterns).
Token 过期,清除缓存后重试:
rm ~/.hermes/skills/wechat-api-lite/scripts/.token_cache
图片用 url 还是 media_id?
Tool parameters are crafted to achieve unintended or unsafe behavior. Parameter abuse can bypass intended safety checks (e.g. shell=True, --force, dangerous glob patterns).
Token 过期,清除缓存后重试:
rm ~/.hermes/skills/wechat-api-lite/scripts/.token_cache
图片用 url 还是 media_id?
Mixing characters from multiple Unicode scripts in a single identifier is a common technique to create visually ambiguous tool names.
Most of the code aligns with the declared purpose: it retrieves access tokens, uploads media, and creates drafts using standard library networking only. However, it also includes an additional capability to query draft counts/list (draft-list / get_draft_list), which is not mentioned in the declared description. Separately, the code comments/docstring state '发布等' (publishing, etc.), but no publish function or CLI command exists in the supplied code, indicating an internal description/behavior inconsistency. This is not a severe mismatch in primary purpose, but there is a material undeclared capability and a stated-but-unimplemented capability.
Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.
**3. Create a draft**
```bash
python3 ~/.hermes/skills/wechat-api-lite/scripts/wechat_api.py \
npx commands without a version suffix (e.g. @1.0.0) create a rug-pull risk if the upstream server is compromised and publishes a malicious update.
npx commands without a version suffix (e.g. @1.0.0) create a rug-pull risk if the upstream server is compromised and publishes a malicious update.
The skill documents commands that read environment-based secrets, access local files, and make outbound network requests to WeChat, but it does not declare any explicit tool scope or permission boundaries. This increases the chance that an agent or user invokes the skill without understanding its access to credentials, local content, and remote upload behavior.
The trigger phrase '创建草稿' is broad enough to match unrelated user requests, which could cause an agent to invoke this skill in the wrong context. Because the skill can upload article content and local media to a remote WeChat service, accidental invocation can lead to unintended data disclosure or unintended remote-side state changes.
The skill instructs users to upload local files and article content to WeChat but does not prominently warn that data is sent to a third-party remote service. In an agent setting, missing disclosure materially increases the risk of users unintentionally exposing sensitive local documents, images, or unpublished content.
The natural-language strings and usage text are entirely in Chinese, which imposes a specific language/locale on users without any opt-in or alternative. Under the policy, forced language constraints should either offer user choice or be explicitly justified as region-specific.
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
print("错误:请先在 config.env 中填入 WECHAT_APP_ID 和 WECHAT_APP_SECRET")
sys.exit(1)
url = f"https://api.weixin.qq.com/cgi-bin/token"
result = wechat_request("GET", url, token=False)
# Build URL manually
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
print("错误:请先在 config.env 中填入 WECHAT_APP_ID 和 WECHAT_APP_SECRET")
sys.exit(1)
url = f"https://api.weixin.qq.com/cgi-bin/token"
result = wechat_request("GET", url, token=False)
# Build URL manually
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
print("错误:请先在 config.env 中填入 WECHAT_APP_ID 和 WECHAT_APP_SECRET")
sys.exit(1)
url = f"https://api.weixin.qq.com/cgi-bin/token"
result = wechat_request("GET", url, token=False)
# Build URL manually
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
print("错误:请先在 config.env 中填入 WECHAT_APP_ID 和 WECHAT_APP_SECRET")
sys.exit(1)
url = f"https://api.weixin.qq.com/cgi-bin/token"
result = wechat_request("GET", url, token=False)
# Build URL manually
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
print("错误:请先在 config.env 中填入 WECHAT_APP_ID 和 WECHAT_APP_SECRET")
sys.exit(1)
url = f"https://api.weixin.qq.com/cgi-bin/token"
result = wechat_request("GET", url, token=False)
# Build URL manually
The access token request embeds APP_ID and APP_SECRET directly into the URL query string. Secrets placed in URLs are more likely to be exposed through logs, debugging output, proxy records, browser/history equivalents, or monitoring systems, increasing credential leakage risk beyond the intended TLS-protected transmission.
result = wechat_request("GET", url, token=False)
# Build URL manually
full_url = f"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={APP_ID}&secret={APP_SECRET}"
req = urllib.request.Request(full_url, method="GET")
with urllib.request.urlopen(req, timeout=30) as resp:
result = json.loads(resp.read().decode())
The script stores a bearer access token in a local plaintext cache file without setting restrictive permissions or warning the user. On multi-user systems or in permissive working directories, another local user or process could read and reuse the token to act against the associated WeChat account until expiry.
The README instructs users to place AppID and AppSecret into a local config file but provides no warning about protecting that file, avoiding commits, or setting restrictive permissions. While common in setup docs, omission of basic secret-handling guidance increases the risk of accidental credential exposure through source control, backups, or shared environments.
The workflow line labels wechat-api-lite create-draft (publish), which states that the command publishes content. However, earlier instructions say the tool only creates drafts and that users must manually preview and publish on mp.weixin.qq.com, so this line actively contradicts the documented behavior.