Back to skill

Security audit

Mermaid Renderer

Security checks for vulnerabilities and agentic risk

Overview

This looks like a real Mermaid diagram renderer, but image export is under-scoped because it can write to arbitrary paths and the instructions say exported images are uploaded to BOS.

Review before installing if you may render private architecture, internal system names, credentials, or business diagrams. Use image export only when external BOS upload is acceptable, and ensure the agent writes only to a dedicated export directory with non-sensitive filenames to avoid accidental overwrites.

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

Unrestricted Image Output Path Allows Overwriting Process-Writable Files

Content
View full analysis
[--image]") print(" --image: 导出为图片,否则输出终端 ASCII") sys.exit(1) mermaid_code = sys.argv[1] output_path = sys.argv[2] mode = sys.argv[3] if len(sys.argv) > 3 else '--terminal' if mode == '--image': result = render_image(mermaid_code, output_path) print(f"图片已保存: {result}") else: result = render_terminal(mermaid_code) print(result) ``` The attacker-controlled path reaches multiple rendering functions, each of which writes directly to that path. A representative sink is: ```python plt.tight_layout() plt.savefig(output_path, dpi=150, bbox_inches='tight', facecolor='white', edgecolor='none') plt.close() return output_path ``` Equivalent `savefig(output_path, ...)` sinks occur in every supported image renderer at lines 182, 398, 447, 652, 816, 1017, and 1198. ### Technical Analysis The CLI accepts `sys.argv[2]` as the output path and passes it directly to Matplotlib's `savefig` operation. There is no canonicalization, destination allowlist, extension validation, existing-file check, or symlink check. Consequently, image mode can create or replace any destination writable by the process. Absolute paths and traversal paths such as `../../target` are not rejected. If the selected destination is a symbolic link, the write may follow that link to its target. The generated content is an image rather than arbitrary attacker-selected bytes, but replacing an existing file can still corrupt data or disrupt applications. This issue does not itself grant additional operating-system privileges. Exploitation remain ...[truncated 1528 chars]
Remediation
View remediation
Path: requested = Path(requested_name) if requested.is_absolute() or ".." in requested.parts: raise ValueError("Unsafe output path") destination = (EXPORT_ROOT / requested).resolve() if EXPORT_ROOT not in destination.parents: raise ValueError("Output must remain inside the export directory") if destination.suffix.lower() != ".png": ...[truncated 306 chars]
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
Findings (9)

Tp4

High
Category
MCP Tool Poisoning
Confidence
91% confidence
Finding

整体上代码的主要目的与声明基本一致,都是 Mermaid 图表渲染,没有发现明显越权、数据访问或无关功能。但按严格的“描述是否准确代表行为”标准,仍存在实质性不一致:1) 描述写明支持“--image/--png 参数”,代码只判断 mode == '--image',未实现 --png;2) 描述给人印象是通用 Mermaid 图表渲染,而代码的图片模式实际上是基于正则和简化布局的手工解析器,仅覆盖 sequenceDiagram、graph/flowchart、pie、classDiagram、gitGraph、stateDiagram、erDiagram,且每类语法支持明显有限,遇到其他 Mermaid 类型会报错。因此应判定为轻到中度描述-行为不匹配。

Content

No source excerpt is available for this finding.

Missing User Warnings

High
Category
Not specified by scanner
Confidence
98% confidence
Finding

The skill documentation says image export generates a PNG and uploads it to BOS, but it does not prominently warn users that a file will be created and transmitted to external storage. This creates a real risk of unintended data exfiltration if the Mermaid diagram contains sensitive architecture, credentials, internal system names, or business information.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
91% confidence
Finding

The skill invokes shell-capable commands (python3.11 -m termaid and scripts/render.py) but does not declare any permissions or allowed-tools scope. This weakens least-privilege controls and makes it harder for the agent runtime or reviewers to understand and constrain what execution capabilities the skill requires.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
92% confidence
Finding

Overly broad trigger phrases can cause the skill to activate for ordinary conversations that mention drawing or generating diagrams, increasing the chance of unintended shell execution or unintended file-generation workflows. In an agent environment, ambiguous routing is a security concern because it can invoke more privileged behavior than the user expected.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The entire reference document is written in Chinese and presents the skill material in a single fixed language, with no indication that users may choose another language or that the skill is intentionally limited to a Chinese-specific audience. Under the policy, a skill that forces a specific language without user opt-in is a natural-language policy concern.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

This code file contains natural-language strings and docstrings that force a specific language/locale for users, including the module description and later CLI output. Under the policy, language-specific behavior should not be imposed without user opt-in or a documented regional justification.

Content

No source excerpt is available for this finding.

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/render.py (reported line 17)May include surrounding context.

python
def render_terminal(mermaid_code: str) -> str:
    """使用 termaid 渲染为终端 ASCII"""
    result = subprocess.run(
        ['python3.11', '-m', 'termaid'],
        input=mermaid_code,
        capture_output=True,

Intent-Code Divergence

Low
Category
Not specified by scanner
Confidence
82% confidence
Finding

模块级文档将两种输出模式分别描述为“终端 ASCII 输出(使用 termaid)”和“图片导出(使用 matplotlib)”,但代码中的终端模式并不是纯库调用,而是通过 subprocess 启动 python3.11 -m termaid。这不改变技能的总体目的,但文档对实现方式的安全/执行模型有误导性,因为实际包含外部进程执行。

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Low
Category
Not specified by scanner
Confidence
77% confidence
Finding

render_image 的文档给人的含义是该函数自身直接用 matplotlib 完成图片渲染,但实现实际上先解析图表类型,再调用多个专门渲染函数处理不同 Mermaid 子语法。虽然底层大多仍依赖 matplotlib,但函数注释与真实控制流不一致,属于文档对代码行为的简化性误述。

Content

No source excerpt is available for this finding.