CVE-2025-65108: md-to-pdf is vulnerable to arbitrary JavaScript code execution when parsing front matter
Summary A Markdown front-matter block that contains JavaScript delimiter causes the JS engine in gray-matter library to execute arbitrary code in the Markdown to PDF converter process of md-to-pdf library, resulting in remote code execution.
Details md-to-pdf uses the gray-matter library to parse front-matter. Gray-matter exposes a JavaScript engine that, when enabled or triggered by certain front-matter delimiters (e.g. ---js or ---javascript), will evaluate the front-matter contents as JavaScript. If user-supplied Markdown is fed to md-to-pdf and the front-matter contains malicious JS, the converter process will execute that code.
PoC const { mdToPdf } = require('md-to-pdf');
var payload = '---javascript\n((require("childprocess")).execSync("calc.exe"))\n---RCE';
(async () => { await mdToPdf({ content: payload }, { dest: './output.pdf'}); })(); Running the PoC on Windows launches the calculator application, demonstrating arbitrary code execution.
Impact
- Remote code execution in the process that performs Markdown->PDF conversion. - If the converter is run in a web app or cloud service, an attacker uploading malicious Markdown can execute arbitrary commands on the
Other sources
md-to-pdf is a CLI tool for converting Markdown files to PDF using Node.js and headless Chrome. Prior to version 5.2.5, a Markdown front-matter block that contains JavaScript delimiter causes the JS engine in gray-matter library to execute arbitrary code in the Markdown to PDF converter process of md-to-pdf library, resulting in remote code execution. This issue has been patched in version 5.2.5.
— MITRE
Affected Software
Event History
Frequently Asked Questions
What is the severity of CVE-2025-65108?
CVE-2025-65108 is classified as a remote code execution vulnerability, which poses a significant security risk.
How do I fix CVE-2025-65108?
To mitigate CVE-2025-65108, upgrade the md-to-pdf library to version 5.2.5 or later.
What causes CVE-2025-65108?
CVE-2025-65108 is caused by a Markdown front-matter block containing a JavaScript delimiter that leads to arbitrary code execution.
Which library is affected by CVE-2025-65108?
The CVE-2025-65108 vulnerability affects the md-to-pdf library that utilizes the gray-matter library.
Can CVE-2025-65108 be exploited remotely?
Yes, CVE-2025-65108 can be exploited by an attacker remotely, potentially leading to complete system compromise.