/

CVE-2026-49493

Severity:

HIGH RISK

(8.8)

Server-Side Code Injection (CWE-94) in Markdown Preview Enhanced Bitfield Code Blocks

CVE-2026-49493

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution

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

Markdown Preview Enhanced before 0.8.28 evaluates the contents of Bitfield fenced code blocks as JavaScript using vm.runInNewContext(), enabling execution of attacker-controlled code on the server.

When a crafted markdown document containing a malicious bitfield block is rendered or exported, the extension may run arbitrary code under the privileges of the hosting process.

Affected context

This vulnerability appears when Markdown Preview Enhanced processes markdown files that use Bitfield fenced code blocks and are rendered in an environment where server-side JavaScript evaluation occurs.

It is most relevant in contexts such as desktop applications, editor backends, or server-side rendering/export pipelines where markdown content may originate from or pass through less-trusted sources (shared documents, collaborative repositories, or imported files).

The issue manifests because the extension treats what should be declarative configuration data as executable code during preview or export.

Exploit preconditions

  • Attack surface: Markdown document ingestion and rendering (preview, export, or automated processing).
  • Required access: Ability to supply or modify a markdown document that will be opened or processed by Markdown Preview Enhanced (e.g., commit to a repo, send a file, or influence shared content).
  • Trigger point: Viewing, previewing, or exporting a markdown file that contains a specially crafted Bitfield fenced code block.
  • Why exploitation is possible: The Bitfield block contents are passed to interpretJS(), which uses vm.runInNewContext() to execute the text as JavaScript instead of treating it as passive data, allowing arbitrary script execution.

Why this happens

The core issue stems from treating user-controlled markdown content as executable JavaScript in a server-side context.

Bitfield fenced code blocks, which conceptually represent data (register or bitfield definitions), were handed to interpretJS(), which evaluates the content through vm.runInNewContext().

This creates a direct code injection path, matching CWE-94: Improper Control of Generation of Code ('Code Injection'), where an attacker crafts input that is executed as code rather than being parsed as structured data.

The fix—switching to JSON5.parse() for parsing bitfield definitions—reflects the correct abstraction: these blocks are configuration-like data, not scripts, and should never invoke a general-purpose code execution engine.

Potential impact

  • Execution of arbitrary JavaScript with the privileges of the markdown rendering/export process
  • Reading, modifying, or deleting files accessible to the host application
  • Exfiltration of sensitive data such as API keys, project files, or credentials stored on disk or in environment variables
  • Installation of additional malicious tooling or persistence mechanisms on the host system, depending on available APIs
  • Lateral movement to other systems or services reachable from the compromised environment

General mitigation guidance

Effective mitigation focuses on removing the code execution surface from data-oriented features and constraining what untrusted content can trigger:

  • Treat all user-supplied markdown and fenced code blocks as untrusted, especially in shared or automated pipelines.
  • Replace any generic "evaluate this text as code" mechanism with strict data parsers (e.g., JSON/JSON5 or schema-validated formats) for configuration-like blocks.
  • Introduce explicit separation between "data" blocks and "script" blocks, and default to non-executable handling unless a narrowly scoped, sandboxed behavior is required.
  • When dynamic evaluation is truly necessary, run it in a hardened sandbox with minimized capabilities, no filesystem or network by default, and explicit allowlists for exposed APIs.
  • Apply least-privilege principles to the host process: limit file system access, network permissions, and OS-level privileges to reduce blast radius if a rendering path is abused.

How teams detect issues like this

Organizations can look for this pattern and similar issues through multiple layers of review and automation:

  • Static analysis: Search for uses of vm.runInNewContext(), eval(), Function(), or similar dynamic evaluation constructs where the source string is influenced by markdown or other user-controlled content.
  • Code review: Flag any feature where "presentation" inputs (markdown, templates, documentation) are passed into generic interpreters instead of being parsed by a restricted data model; review custom markdown extensions and fenced-block handlers carefully.
  • Policy enforcement: Define secure coding guidelines that prohibit or tightly regulate dynamic code evaluation mechanisms, especially in content processing pipelines.
  • Automated tooling: Use linters or security scanners that include rules for dangerous JavaScript runtime APIs and integrate them into CI/CD to catch regressions before release.

Sources

SourceLink
github.comgithub.com/shd101wyy/vscode-markdown-preview-enhanced/releases/tag/0.8.28
vulncheck.comvulncheck.com/advisories/markdown-preview-enhanced-arbitrary-code-execution-via-bitfield-interpretjs

Frequently asked

questions

It can be, depending on how markdown files are obtained. If an attacker can cause a target user or system to open or render a malicious markdown file (for example via a shared repository, email attachment, or web-based markdown viewer tied to the same code), the attack can be triggered without local shell access.

The attacker needs the ability to provide or modify a markdown document that is subsequently processed by Markdown Preview Enhanced. They do not need direct code execution on the target beforehand; the execution arises when the victim's environment renders or exports the document.

The safest pattern is to avoid executing user-controlled content as code altogether. For data-like sections (such as bitfield or configuration blocks), use strict parsers tied to an explicit schema, and remove any dependency on general-purpose interpreters or dynamic evaluation APIs.

Design markdown and document processing features under a "data, not code" assumption, enforce that untrusted content remains non-executable, and restrict any necessary scripting to narrowly scoped, sandboxed environments. Combine this with secure coding policies, code review focused on evaluation APIs, and static analysis rules that highlight dynamic code execution paths fed by user input.

Find out what's already
exploitable in your codebase.