Summary
A code injection vulnerability in the Visual Studio Code extension "Markdown Preview Enhanced" v0.8.18 allows arbitrary code execution when a malicious Markdown (.md) file is opened and previewed.
If an attacker can convince a user to open a crafted Markdown file in this extension, they may be able to execute arbitrary commands on the user's machine under the user's privileges.
Affected context
This vulnerability affects environments where Visual Studio Code is installed with the Markdown Preview Enhanced extension at version 0.8.18.
The risk materializes when users open untrusted or externally supplied Markdown (.md) files and render them using the extension's preview functionality.
The issue stems from the extension interpreting or evaluating Markdown content in a way that permits embedded code or commands to influence the host environment beyond the intended preview sandbox.
Exploit preconditions
- Attack surface: Visual Studio Code instance running the Markdown Preview Enhanced v0.8.18 extension.
- Required access: Ability to deliver or influence a Markdown (.md) file that the target user will open in VS Code (e.g., via email, source repository, file share, or collaboration tools).
- Trigger point: User opens the crafted Markdown file and activates the Markdown preview (either automatically or manually) using the vulnerable extension.
- Why exploitation is possible: The extension processes Markdown content in a way that allows embedded constructs to be interpreted as executable code or commands, without adequate sanitization, escaping, or sandboxing, enabling code injection on the host.
Why this happens
This bug is an instance of CWE-94: Improper Control of Generation of Code ('Code Injection').
The Markdown Preview Enhanced extension dynamically interprets or generates code based on Markdown file content, and it fails to enforce strict boundaries between untrusted document data and executable logic.
Dangerous patterns often include:
- Evaluating user-controlled strings as code or shell commands.
- Translating Markdown directives into scripts or command-line calls without strict validation.
- Bridging from the preview environment to the host OS or Node.js APIs without robust input sanitization and context-aware escaping.
As a result, specially crafted Markdown elements can alter the code that gets executed on the user's machine when the preview is rendered.
Potential impact
- Execution of arbitrary commands or scripts on the developer's machine.
- Theft of sensitive data accessible to the user account (API keys, SSH keys, configuration files, project source code).
- Installation of malware or backdoors on the user's system.
- Use of compromised developer workstations as a pivot point into source repositories or CI/CD pipelines.
- Manipulation or exfiltration of application source code and build artifacts.
General mitigation guidance
Effective mitigations focus on eliminating code execution paths that are influenced directly by document content and constraining what the preview engine can do:
- Treat all Markdown content as untrusted data and never evaluate it as code or shell commands.
- Avoid generic
eval-style mechanisms or dynamic code generation based on document content; instead, use fixed, declarative rendering logic. - Implement strict whitelisting of supported Markdown extensions or directives, parsing them with robust, context-aware sanitization.
- Enforce sandboxing for any executable logic related to previews (e.g., use restricted runtimes or inter-process communication with no direct shell access).
- Apply the principle of least privilege for any helper processes or APIs that interact with the OS, minimizing capabilities available to the extension.
- Provide configuration options for users to disable any "active" or executable Markdown features, defaulting to the safest behavior for untrusted files.
How teams detect issues like this
Detection efforts can focus on both code-level and usage-level signals:
- Static analysis and code scanning:
- Flag any use of
eval, dynamicFunctionconstructors, or similar evaluation APIs that process Markdown-derived strings. - Detect places where Markdown tokens are concatenated into shell commands, script blocks, or OS-level calls without strong validation.
- Identify bridges from the extension to Node.js/OS APIs that accept untrusted document input.
- Code review practices:
- Review features that interpret custom Markdown directives, code blocks, or embedded scripts for strict separation of data and code.
- Examine any preview-related code that spawns subprocesses, accesses the filesystem, or interacts with the OS.
- Policy and tooling:
- Use extension security reviews or automated tooling that checks for dangerous APIs in VS Code extensions.
- Enforce organization-wide policies that require security review for extensions that execute or transform user-supplied content into code.

