
CVE-2024-4367
This project demonstrates and analyzes CVE-2024-4367, a high-severity vulnerability in Mozilla’s PDF.js library that allows arbitrary JavaScript execution through improper type checking in font handling code. Our research shows how a maliciously crafted PDF can execute JavaScript in contexts like Electron apps, potentially escalating to remote code execution.
🔗 GitHub Repository: Hacking-pdf.js-vulnerability
fontMatrix in embedded fonts.ex1.pdf and ex-gist.pdf show alerts or remote-script execution.src/components/ReactPdfViewer.tsx – React viewer built with react-pdf 5.7.2 (bundles vulnerable pdfjs-dist 2.16.105)ex1.pdf – malicious PDF triggering an alertex-gist.pdf – malicious PDF that fetches & executes remote JSCVE-2024-4367_Report_Hacking_Project.pdf – full technical report and exploit analysisPDF.js’s fontMatrix array elements were improperly validated—accepting strings injected directly into JavaScript compiled with new Function(...). This allows attackers to craft malicious font data, causing arbitrary code execution when eval-like operations are permitted.
Example vulnerable code path:
fontMatrix = ["alert('XSS')", 0, 0, 1, 0, 0]; // Injected payload
// Results in compiled function like:
function drawGlyph() {
transform("alert('XSS')", 0, 0, 1, 0, 0); // Unsafe execution
}
To mitigate this vulnerability and protect applications embedding PDF.js (or libraries that bundle it), adopt the following measures:
isEvalSupported = false in PDF.js to turn off dynamic Function compilation.typeof checks on all user-supplied values (e.g., the fontMatrix array).package.json/yarn.lock up-to-date and auto-apply security patches.Add a strict Content-Security-Policy:
Content-Security-Policy: script-src 'self'; object-src 'none';