Summary
Markdown Preview Enhanced before 0.8.28 evaluates WaveDrom diagram definitions using eval() on untrusted markdown content, allowing arbitrary JavaScript execution in all render paths.
When a user previews, presents, or exports a crafted markdown document, an attacker-controlled WaveDrom block or script can execute code, which can be chained to arbitrary file write on the victim system.
Affected context
This vulnerability occurs in environments using Markdown Preview Enhanced (prior to 0.8.28) to render markdown documents that contain WaveDrom diagrams.
Any context where markdown is rendered with:
- Live preview
- Presentation mode
- HTML export
is affected, because all of these paths process WaveDrom content.
The issue manifests when WaveDrom definitions are taken directly from user-controlled markdown or from raw HTML <script type="WaveDrom"> blocks and are then evaluated using eval() or equivalent helper functions, without first constraining the input to a safe data format.
Exploit preconditions
- Attack surface: Markdown rendering pipeline within Markdown Preview Enhanced (editor extension / application).
- Required access: Ability to supply or influence the markdown content being opened (e.g., sharing a crafted file, repository, or snippet that a victim opens in the extension).
- Trigger point: User opens, previews, presents, or exports the malicious markdown so that WaveDrom diagrams are rendered.
- Why exploitation is possible: The WaveDrom data is passed to
eval()(or helper functions that calleval()) directly, without restricting it to inert JSON data. This allows attacker-controlled JavaScript to run with the privileges of the rendering context, which in turn can access extension APIs or host integration that enable file system writes.
Why this happens
The root cause is the use of eval() to interpret WaveDrom diagram definitions embedded in markdown, instead of treating them as strictly structured data.
This maps to CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection'), where external input is concatenated or passed into a dynamic evaluation function.
By allowing WaveDrom blocks and <script type="WaveDrom"> elements to be evaluated directly, the implementation collapses the boundary between content and code: diagram text is treated as executable JavaScript rather than as data.
In this pattern, any attacker who can influence the markdown can inject arbitrary JavaScript that runs when the renderer processes the document, enabling further abuse such as invoking file APIs exposed by the environment.
Potential impact
- Arbitrary JavaScript execution in the context of the Markdown Preview Enhanced renderer.
- Arbitrary file write on the victim machine, subject to the capabilities exposed by the host application or extension environment.
- Manipulation or exfiltration of sensitive project files opened in the same environment.
- Tampering with exported HTML or slides (e.g., injecting backdoors into shared outputs).
- Potential lateral movement by planting malicious files or scripts in trusted project locations.
General mitigation guidance
Effective mitigation focuses on treating diagram definitions as data, not code, and tightening the evaluation surface:
- Replace
eval()-based parsing with data-only parsers (e.g., strict JSON/JSON5 parsing) that do not execute arbitrary code. - Constrain WaveDrom inputs to a well-defined schema, rejecting or ignoring any constructs outside the expected diagram data format.
- Sanitize and normalize
<script type="WaveDrom">contents to inert data structures before passing them to any rendering logic. - Ensure that rendering helpers (such as WaveDrom.ProcessAll()) operate purely on parsed data objects and never invoke general-purpose code evaluation on user input.
- Run markdown rendering components with least privilege, minimizing their ability to read or write files beyond what is strictly required.
- Treat all markdown content as untrusted, even when it originates from internal repositories, and avoid special trust assumptions for local files.
How teams detect issues like this
Detection can focus on both code-level patterns and behavioral indicators:
- Static analysis and code review:
- Search for uses of
eval(),new Function(), or similar dynamic evaluation primitives applied to values derived from markdown or HTML content. - Flag any WaveDrom-related code paths that construct JavaScript snippets from strings and then execute them.
- Enforce policies that require diagram or markup parsers to use data-only parsing APIs (e.g., JSON/JSON5) and prohibit dynamic evaluation of content.
- Automated tooling:
- Integrate static application security testing (SAST) rules that detect CWE-95 patterns in extensions or plugins that parse user text.
- Use dependency or plugin audits to scan for known eval-based rendering primitives.
- Runtime/behavioral monitoring (where applicable):
- Instrument the environment to log unexpected file write operations initiated by rendering components.
- Monitor for suspicious script constructs within documents that are meant to contain only diagram data.

