Back to skill

Security audit

Matplotlib Chinese Font

Security checks for vulnerabilities and agentic risk

Overview

This skill is a coherent Matplotlib Chinese-font troubleshooting helper; its main caution is an explicit cache-clearing step that deletes a local Matplotlib cache directory.

Install only if you want Chinese-font help for Matplotlib. Before running the cache-clearing command or scripts/clear_cache.py, confirm you are comfortable deleting your local Matplotlib cache/config directory so Matplotlib can rebuild it; avoid running it in an unusual environment where Matplotlib's cache path may have been redirected.

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

Unvalidated Recursive Deletion of the Matplotlib Cache Directory

Content
View full analysis

Vulnerability Details

File Location: scripts/clear_cache.py, lines 7–12
Vulnerability Type: Unvalidated recursive directory deletion
Risk Level: Medium

python
cache_dir = matplotlib.get_cachedir()
print(f"字体缓存目录: {cache_dir}")

if os.path.exists(cache_dir):
    shutil.rmtree(cache_dir)
    print("✅ 字体缓存已清除")

Technical Analysis

The script passes the directory returned by matplotlib.get_cachedir() directly to shutil.rmtree(). It does not verify that the resolved path is a dedicated Matplotlib cache directory, that it resides beneath an expected trusted parent, or that it is not a symbolic link or an overly broad directory such as the user's home directory.

Matplotlib's cache location can depend on runtime configuration and environment settings. If an attacker, unsafe launcher, or compromised execution environment can influence that location, the script may recursively delete an unrelated directory. The existence check does not establish that the target is safe; it only confirms that a filesystem entry exists.

Attack Path

  1. An attacker gains control over, or influences, the environment or Matplotlib configuration used to launch the script.
  2. The attacker causes matplotlib.get_cachedir() to resolve to an existing directory containing valuable user-accessible files.
  3. The user follows the documented troubleshooting guidance and runs python3 scripts/clear_cache.py.
  4. The script calls shutil.rmtree(cache_dir) without validating the target.
  5. The target directory and its contents are recursively deleted with the privileges of the user running the script.

Impact Assessment

Successful exploitation can cause destructive loss of files and directories writable by the executing user. The vulnerability does not independently grant elevated privileges, remote code execution, or access beyond the current process's permissions. Its scope is limited by the filesystem privileges of ...[truncated 155 chars]

Remediation
View remediation

Remediation Suggestions

  • Resolve the target to a canonical absolute path before deletion.
  • Allow deletion only when the path is beneath an explicitly trusted cache parent and has the expected Matplotlib-specific directory structure.
  • Reject empty paths, filesystem roots, user home directories, current working directories, and other broad or sensitive locations.
  • Detect and reject symbolic links in the target path and relevant parent components.
  • Prefer deleting only known Matplotlib cache files rather than recursively deleting the entire directory.
  • Display the validated target and require explicit user confirmation before destructive removal.
  • Fail closed when path validation is inconclusive.
  • Consider using a guarded implementation such as:
python
from pathlib import Path
import matplotlib
import shutil

cache_dir = Path(matplotlib.get_cachedir()).expanduser()
resolved = cache_dir.resolve(strict=True)
home = Path.home().resolve()

forbidden = {
    Path("/").resolve(),
    home,
    Path.cwd().resolve(),
}

if resolved in forbidden:
    raise RuntimeError(f"Refusing to delete unsafe path: {resolved}")

if resolved.is_symlink() or "matplotlib" not in resolved.name.lower():
    raise RuntimeError(f"Unexpected Matplotlib cache path: {resolved}")

confirmation = input(f"Delete Matplotlib cache directory '{resolved}'? [y/N] ")
if confirmation.lower() == "y":
    shutil.rmtree(resolved)

The exact trusted-parent policy should be tailored to the operating systems supported by the Skill rather than relying solely on a directory-name check.

Vulnerability Patterns
  • Tool MisuseTool Parameter Abuse, Chaining Abuse, Unsafe Defaults
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (12)

Tp4

High
Category
MCP Tool Poisoning
Confidence
95% confidence
Finding

The declared purpose says the skill configures Chinese fonts for matplotlib plotting, implying setup of font settings for rendering Chinese text. The supplied code does not configure fonts or plotting behavior at all. Instead, it locates matplotlib's cache directory and recursively deletes it from the local filesystem. While clearing the font/cache may be related to troubleshooting garbled Chinese text, the primary behavior is cache deletion, which is a materially different capability and involves filesystem modification that is not reflected in the description.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
95% confidence
Finding

The declared description says the skill configures Chinese fonts for matplotlib plotting, implying it would set matplotlib font parameters or otherwise modify plotting configuration to fix garbled Chinese text. The supplied code does not configure anything. It only reads the font list from matplotlib's font manager, filters names using keyword heuristics, and prints matching fonts. This is a materially different primary purpose: font discovery/inspection rather than font configuration. There are no suspicious extra permissions or unrelated resource accesses beyond font enumeration, but the behavior still does not match the declared description.

Content

No source excerpt is available for this finding.

Tool Parameter Abuse

High
Category
Tool Misuse
Confidence
90% confidence
Finding

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).

Content

Scanner excerpt · SKILL.md (reported line 61)May include surrounding context.

  1. 清除字体缓存
    bash
    rm -rf ~/.matplotlib
    
    或运行:
    bash

Tool Parameter Abuse

High
Category
Tool Misuse
Confidence
90% confidence
Finding

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).

Content

Scanner excerpt · references/troubleshooting.md (reported line 13)May include surrounding context.

  1. 清除字体缓存
    bash
    rm -rf ~/.matplotlib
    
    或运行:
    bash

Tool Parameter Abuse

High
Category
Tool Misuse
Confidence
90% confidence
Finding

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).

Content

Scanner excerpt · SKILL.md (reported line 61)May include surrounding context.

  1. 清除字体缓存
    bash
    rm -rf ~/.matplotlib
    
    或运行:
    bash

Tool Parameter Abuse

High
Category
Tool Misuse
Confidence
90% confidence
Finding

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).

Content

Scanner excerpt · references/troubleshooting.md (reported line 13)May include surrounding context.

  1. 清除字体缓存
    bash
    rm -rf ~/.matplotlib
    
    或运行:
    bash

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The skill is explicitly scoped to configuring Chinese fonts and all usage guidance, examples, and labels are presented only for Chinese-language output. Under the policy rule, a skill that forces a specific language or locale should offer user choice or clearly document a justified locale-specific constraint, which this file does not do.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

This markdown file includes a recursive deletion command (rm -rf ~/.matplotlib) as a troubleshooting step, but it does not warn the user that the command deletes a local cache directory. For markdown files, safety-affecting behaviors that may impact user data or system state should include a clear warning or disclosure.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The script recursively deletes the entire matplotlib cache directory with shutil.rmtree(), which is a destructive filesystem operation rather than simple font configuration. While likely intended to refresh font metadata, it can remove unrelated cached state for the current user and is broader than necessary for the stated skill purpose.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

This code contains user-facing description and CLI messages exclusively in Chinese, including the module docstring and usage/help output. The file does not offer a language/locale option or explain that the tool is intentionally limited to a Chinese-speaking context, which conflicts with the policy against forcing a specific language without user opt-in.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
81% confidence
Finding

The file forces a single language presentation throughout the skill documentation, with no indication that the user can select another language or that the skill is intentionally limited to a Chinese-speaking audience. The policy requires flagging language or locale constraints unless they are opt-in or clearly documented and justified.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
88% confidence
Finding

The file’s docstring, comments, and user-facing print messages are entirely in Chinese, which imposes a specific language on users without offering any locale or language choice. Under the policy for natural-language violations, forcing a language without opt-in is in scope even for code files.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.