Back to skill

Security audit

mermaid-canvas

Security checks for vulnerabilities and agentic risk

Overview

This Mermaid rendering skill is purpose-aligned but needs Review because it renders user diagram text in a browser with unsafe script/HTML handling and under-disclosed external network paths.

Install only if you are comfortable reviewing diagram content before rendering and avoiding sensitive diagrams unless external network use is acceptable. Prefer a version that HTML-escapes Mermaid input, uses strict Mermaid security settings, pins or vendors Mermaid locally, and makes Feishu or mermaid.ink upload explicit opt-in actions.

Vulnerability Patterns
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • 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
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (3)

T09 · Insecure Skill Coding Practices

Error
Location
scripts/mermaid_render.py:53
Finding

Unescaped Mermaid Input Allows HTML and JavaScript Injection

Content
View full analysis
body {{ margin: 20px; background: {background_color}; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }} pre.mermaid {{ display: flex; justify-content: center; align-items: center; min-height: {min_height}px; max-width: 100%; overflow: visible; }} .mermaid svg {{ max-width: 100% !important; height: auto !important; }}
text
{mermaid_code}
  
``` ```python def escape_mermaid_code(code: str) -> str: """Escape Mermaid code while preserving indentation.""" lines = code.strip().split('\n') # Preserve indentation but remove trailing whitespace result = [] for line in lines: result.append(line.rstrip()) return '\n'.join(result) def generate_html( mermaid_code: str, theme: str = "default", background_color: str = "white" ) -> str: # "Escaping" does not perform HTML entity encoding escaped_code = escape_mermaid_code(mermaid_code) line_count = len(escaped_code.split('\n')) min_height = max(300, line_count * 30) html = HTML_TEMPLATE.format( mermaid_code=escaped_code, theme=theme, background_color=background_color, min_height=min_height ) return html ``` ### Technical Analysis The function named `escape_mermaid_code()` does not perform HTML escaping. It only strips surrounding whitespace and removes trailing whitespace from each line. The resulting attacker-controlle ...[truncated 2400 chars]
Remediation
View remediation
str: normalized = '\n'.join( line.rstrip() for line in code.strip().splitlines() ) return html.escape(normalized, quote=True) ``` 2. Prefer constructing the page so that untrusted diagram source is assigned through `textContent` rather than HTML interpolation: ```html
text
``` 3. Validate diagram input against an explicit allowlist and reject HTML tags, Mermaid directives, link callbacks, and unsupported interactive constructs. 4. Render diagrams in an isolated, ephemeral browser profile without authenticated sessions or access to sensitive browser state. 5. Apply a restrictive Content Security Policy that blocks inline scripts, navigation, frames, and unauthorized network destinations. 6. Restrict renderer network access to the minimum required destinations, or remove network access by vendoring Mermaid locally. 7. Add regression tests using payloads containing ``, `

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/mermaid_render.py:56
Finding

Mermaid Loose Security Mode Expands the Active-Content Attack Surface

Content
View full analysis
mermaid.initialize({ startOnLoad: true, theme: '{theme}', securityLevel: 'loose', fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', flowchart: { htmlLabels: true, curve: 'basis' }, sequence: { actorMargin: 50, boxMargin: 10, boxTextMargin: 5, noteMargin: 10, messageMargin: 40 } }); ``` The same insecure configuration is documented in `SKILL.md:70`: ```javascript mermaid.initialize({ startOnLoad: true, theme: 'default', securityLevel: 'loose' }); ``` ### Technical Analysis The renderer explicitly configures Mermaid with `securityLevel: 'loose'` while processing diagram source that may originate from users. Loose mode permits more HTML-oriented and interactive Mermaid functionality than strict mode. The configuration also enables `htmlLabels`, increasing reliance on HTML-based rendering. This setting weakens Mermaid's built-in restrictions and increases the consequences of malicious Mermaid constructs, links, callbacks, or active content. It is particularly unsafe when combined with the separate raw HTML interpolation vulnerability. The reference documentation describes syntax-safety conventions, but those conventions only address parse compatibility, such as reserved node identifiers and label quoting. They do not provide a security boundary against malicious diagrams. ### Attack Path 1. An attacker submits Mermaid source containing interactive, link-oriented, or HTML-capable constructs. 2. The source passes the minimal diagram-type validation. 3. Mermaid processes the diagram under `securityLevel: 'loose'`. 4. Features that would be restricted under strict mode may be rendered with fewer safeguards. 5. A u ...[truncated 807 chars]
Remediation
View remediation

T03 · Remote Payload Retrieval and Execution

Warning
Location
scripts/mermaid_render.py:30
Finding

Mutable Remote JavaScript Is Retrieved and Executed During Rendering

Content
View full analysis
``` The same runtime dependency is prescribed in `SKILL.md:57`: ```html ``` ### Technical Analysis Every rendered HTML file retrieves and executes JavaScript from jsDelivr. The URL pins only the major Mermaid version (`@11`) rather than an exact immutable release. Its effective contents can therefore change after the Skill package has been audited. No Subresource Integrity hash is supplied, so the browser has no project-defined cryptographic mechanism to verify that the downloaded script matches a reviewed artifact. This creates a runtime supply-chain boundary involving the package publisher, package registry, CDN, DNS, transport trust, and future releases selected by the floating version. Although HTTPS protects transport against ordinary network interception, it does not prevent execution of a compromised upstream release, CDN-served artifact, or unexpected future version matching the broad version selector. ### Attack Path 1. A user requests Mermaid rendering. 2. The Skill generates an HTML document referencing `mermaid@11` on jsDelivr. 3. The rendering browser opens the generated document. 4. The browser requests the current script selected by the floating major-version URL. 5. If the upstream package, release process, registry account, or CDN content is compromised—or if a future compatible release is unsafe—the browser downloads altered JavaScript. 6. The remote JavaScript executes automatically in the rendering page. 7. The payload can manipulate generated output and use browser capabilities available to that page. ### Impact Assessment A compromised or unexpect ...[truncated 618 chars]
Remediation
View remediation
``` 3. Generate and verify a Subresource Integrity hash for the exact reviewed artifact. 4. Lock dependency versions and review updates through a controlled process rather than resolving them at runtime. 5. Restrict renderer egress so it cannot contact arbitrary destinations. 6. Add a restrictive Content Security Policy limiting scripts to the exact approved local file or hash. 7. Verify packaged dependency checksums during build or installation and fail closed if verification does not succeed. ]]>
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
Findings (11)

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The trigger list includes very broad phrases such as ‘画图’ and generic chart-generation language, which can cause the skill to activate in contexts the user did not intend. Over-broad activation increases the chance of processing unrelated or sensitive user content through browser rendering and optional external upload paths.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The catch-all guidance to use this skill for ‘any request involving creating diagrams’ is ambiguous and can lead to unintended invocation. In a skill that renders untrusted content in a browser and may transmit outputs externally, accidental invocation materially expands exposure and weakens user consent.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

The skill advertises direct upload of rendered images to Feishu without clearly warning that user-supplied content may be transmitted to an external service. This creates a privacy and data-handling risk because users may include sensitive architecture, process, or business information in diagrams without understanding it will leave the local environment.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The technical workflow includes an optional Feishu upload step but does not pair it with a clear warning or consent checkpoint. Even if optional, documenting the behavior as part of the normal flow makes it more likely to be implemented or invoked without adequate notice, exposing potentially sensitive diagram data to third parties.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The skill’s stated ‘安全语法规范’ is undermined by the HTML template initializing Mermaid with securityLevel: 'loose', which weakens Mermaid’s built-in protections for untrusted diagram content. Because the skill renders user-provided Mermaid inside a browser context and loads a remote Mermaid runtime, permissive rendering can enable script/HTML injection or active content execution depending on Mermaid features and browser behavior.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The module docstring shows examples such as producing '/tmp/output.png' and using '--upload-feishu', and the dependency comment mentions an optional Feishu upload tool. In reality, main() only validates Mermaid code, generates HTML, and prints instructions to use a browser tool manually; the upload flag and doc ID are parsed but never used.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

In the fallback path, arbitrary Mermaid source is base64-encoded and sent to the external mermaid.ink service without an explicit opt-in or prominent warning. Mermaid diagrams can contain sensitive business logic, architecture, identifiers, or embedded text, so this behavior can leak confidential data to a third party and may violate data-handling requirements.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The function documentation says it 'renders Mermaid code to PNG' and returns the rendered image path, but the main execution path only generates HTML, saves it to a temporary file, and returns that HTML path for an external browser tool to use. This is an active contradiction between the documented behavior and the actual code behavior, not merely an omitted detail.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
83% confidence
Finding

The HTML template fetches Mermaid from a remote CDN without warning users that rendering requires outbound network access. This can leak metadata such as timing, IP/environment details, and introduces a supply-chain risk if the remote dependency changes or is compromised.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
87% confidence
Finding

This markdown reference file is entirely written in Chinese, including the title and all diagram labels, with no indication that language selection is optional or that the file is intended only for a Chinese-language audience. Under the policy rule for natural-language violations, forcing a specific language without user opt-in can be a locale policy issue.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
86% confidence
Finding

The file title and all instructional content are written in Chinese, which imposes a specific language on users. Under the policy, a language constraint should either be optional for the user or clearly justified as region-specific; this document does neither.

Content

No source excerpt is available for this finding.