Untrusted note content can execute arbitrary code via Mermaid click directives in a webview with full filesystem access

Open
#1,324 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
15/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
tauri, typescript

Research direction

Start with the mermaid.initialize call in src/app/core/main/editor/markdown/mermaid-extension.tsx, which sets securityLevel to 'loose', and with the capability grants in src-tauri/capabilities/default.json, which scope fs and opener permissions to "**" for the main and editor-* webviews. Reproducing the click-directive execution needs a crafted diagram in a note, and the report gives no steps yet. Done means the click path is confirmed, and the security level and webview permissions are narrowed without breaking diagram rendering. Security reports like this usually need a maintainer's direction first.

Written by the indexing model from the issue text.

Description

Summary

Affected versions: confirmed on master HEAD, commit as of 2026-10-31.

src/app/core/main/editor/markdown/mermaid-extension.tsx initializes Mermaid with securityLevel: 'loose', which permits click directives in diagram source (click <node> href "javascript:..." or click <node> call <fn>()) to execute arbitrary JavaScript when a user clicks the rendered diagram node. Mermaid diagram source is ordinary note content under full attacker control (an imported file, a synced/shared note). The webviews that render notes (main, editor-*) are granted fs:write-all/fs:read-all/opener:allow-open-path, all scoped to "**" in src-tauri/capabilities/default.json.

Details

mermaid-extension.tsx:

mermaid.initialize({
  startOnLoad: false,
  theme: 'default',
  securityLevel: 'loose',
  fontFamily: 'inherit',
})

src-tauri/capabilities/default.json (relevant excerpt):

{
  "webviews": ["main", "screenshot", "pdf-print-*", "editor-*"],
  "permissions": [
    "fs:default",
    { "identifier": "fs:read-all", "allow": [{ "path": "**" }] },
    { "identifier": "fs:write-files", "allow": [{ "path": "**" }] },
    "fs:write-all",
    { "identifier": "opener:allow-open-path", "allow": [{ "path": "**" }] }
  ]
}

A note containing a crafted Mermaid diagram with a click directive achieves full filesystem read/write the moment a user clicks the rendered diagram node.

Steps To Reproduce

(available upon request)

Impact

A note the victim merely opens and clicks once achieves arbitrary file write/read anywhere on the filesystem the OS user account can reach (overwrite shell profiles/cron/systemd user units/SSH keys for persistence, or exfiltrate files via the also-unrestricted http:allow-fetch permission). Notes are explicitly a shareable/syncable artifact in this application's own design, so a malicious or compromised shared note is a realistic delivery vector, not a contrived scenario.

Dominant language
TypeScript
Stars
12.9k
Forks
975
Avg merge
20h 27m
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from codexu/note-gen

All issues in codexu/note-gen

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.