/

CVE-2025-65716

Severity:

HIGH RISK

(8.8)

Code Injection in VS Code Extension Markdown Preview

CVE-2025-65716

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution on Developer Workstations

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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, dynamic Function constructors, 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.

Sources

SourceLink
github.comgithub.com/shd101wyy/markdown-preview-enhanced
ox.securityox.security/blog/cve-2025-65716-markdown-preview-enhanced-vscode-vulnerability/

Frequently asked

questions

It can be exploited remotely in the sense that an attacker only needs to deliver a malicious Markdown file (for example via email, repository, or shared drive) and convince the victim to open it in VS Code with the vulnerable extension enabled; no direct network access to the victim's machine is required.

The attacker needs the ability to provide or influence a Markdown file that the victim opens with Markdown Preview Enhanced v0.8.18.

They do not need prior access to the victim's system or VS Code environment, but exploitation depends on user interaction.

Do not execute or evaluate any content that originates from documents.

Replace dynamic evaluation and command construction with strictly defined rendering logic, ensure all document-derived data is treated as plain text, and isolate any necessary execution in a constrained sandbox with minimal privileges.

Design extensions around a data-only rendering model, conduct security-focused reviews for any features that run code or invoke system commands, use static analysis to detect dynamic evaluation patterns, and adopt a default posture that treats all user-supplied files as untrusted and potentially malicious.

Find out what's already
exploitable in your codebase.