Summary
Markdown Preview Enhanced with the crossnote engine contains a JavaScript code injection flaw in its WaveDrom rendering pipeline that allows arbitrary script execution inside the VS Code webview.
When a crafted Markdown document includes a malicious wavedrom fenced code block, its contents are passed unsafely into window.eval(), enabling attackers to run JavaScript that can abuse extension messaging and trigger arbitrary file writes on the local filesystem.
Affected context
The vulnerability appears in environments where:
- The Markdown Preview Enhanced extension is installed (0.8.x) with crossnote engine 0.9.28
- WaveDrom fenced code blocks are rendered within the VS Code webview
- Markdown content may originate from untrusted or shared sources (e.g., cloned repositories, documentation, notes)
The risk is specific to the WaveDrom rendering path that interprets fenced wavedrom code blocks and evaluates them in the browser-like webview context.
Exploit preconditions
- Attack surface: Opening or previewing a malicious Markdown file in VS Code with Markdown Preview Enhanced enabled.
- Required access: Ability to introduce or modify Markdown documents rendered by the extension (e.g., committing to a repo, sharing project files, or editing shared notes).
- Trigger point: User opens the Markdown file and activates the preview (automatic or manual) that processes the WaveDrom fenced code block.
- Why exploitation is possible: The WaveDrom block's content is passed directly to
window.eval()without sanitization or sufficient validation, allowing attacker-controlled JavaScript to execute inside the webview. That script can interact with the extension's message-passing mechanisms to initiate arbitrary file writes.
Why this happens
The core issue is a classic code injection pattern: treating attacker-controlled text as executable code.
In the WaveDrom rendering pipeline, the extension forwards the raw content of a wavedrom fenced block to window.eval() in the webview. This effectively grants the author of the Markdown document the ability to inject arbitrary JavaScript into the preview context. Because the webview can communicate with the extension host via message passing, this injected code can invoke filesystem-related functionality exposed by the extension, escalating from in-webview script execution to unintended local file manipulation.
Conceptually, this maps to CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code, where untrusted input is dynamically evaluated without being constrained to a safe subset or subject to robust sanitization.
Potential impact
- Execution of arbitrary JavaScript within the VS Code webview when a crafted Markdown file is previewed
- Abuse of extension message-passing APIs to trigger arbitrary file writes on the local filesystem
- Overwriting or planting files in the workspace, potentially leading to:
- Source code tampering
- Malicious configuration changes
- Introduction of backdoored scripts or build artifacts
- Potential pivot to further compromise of the developer environment, depending on what the extension exposes to the webview
- Loss of integrity and possible confidentiality of project files opened in the affected workspace
General mitigation guidance
Effective mitigation focuses on eliminating dynamic evaluation of untrusted content and tightening the interaction between the webview and the extension host:
- Replace
eval-based rendering with a deterministic WaveDrom parsing and rendering routine that interprets structured data rather than executing arbitrary JavaScript. - Restrict the WaveDrom syntax to a safe data-only subset (e.g., JSON-like structures) and validate input against a strict schema before processing.
- Ensure any code paths that must interpret user-controlled content operate with a whitelist of allowed operations rather than generic execution primitives.
- Harden webview–extension communication by:
- Limiting message types and payloads to narrowly-scoped, well-validated commands.
- Enforcing strict checks on what operations can be initiated from the webview, especially those touching the filesystem.
- Apply least-privilege principles to file operations initiated by the extension, constraining writes to intended directories and file types.
- Consider providing security-focused configuration options that disable or strictly limit execution-like features in Markdown previews when handling untrusted documents.
How teams detect issues like this
Detection can leverage both code-centric and workflow-centric controls:
- Static analysis and code scanning:
- Flag usage of
eval,Function, or equivalent dynamic execution constructs in extension code, especially when fed by document content or webview messages. - Identify webview scripts that process fenced code blocks and check for direct evaluation or unvalidated concatenation into executable contexts.
- Code review practices:
- Review any rendering pipelines that transform Markdown fenced blocks into executable JavaScript or complex logic.
- Inspect webview message handlers for filesystem operations triggered by loosely validated or generic commands from the UI layer.
- Policy enforcement:
- Enforce extension development guidelines that prohibit dynamic evaluation of user-supplied content.
- Integrate automated checks in CI/CD for sensitive APIs and patterns (e.g., regex or linter rules for
evaland similar constructs). - Runtime and behavioral monitoring (where applicable):
- Monitor for unusual file write patterns originating from the extension's process when opening or previewing Markdown files from untrusted locations.

