Inside Cve 2024 4367 Arbitrary Javascript Execution Via Pdf Js
PDF.js versions before 4.2.67 failed to validate the FontMatrix array in a PDF's font definition, allowing non-numeric values to be embedded into dynamically generated JavaScript. An attacker could upload a crafted PDF that executes arbitrary JavaScript when rendered, potentially stealing tokens or performing actions as the victim.
PDF.js as the name suggests is a javascript open source library. This library is primarily used for parsing and rendering PDFs in web browsers & desktop applications.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the FontMatrix array from the PDF was interpolated directly into a generated JavaScript string passed to the transform function, without validating that each element was numeric.
Impact
An attacker could execute JavaScript in the victim's browser when a crafted PDF is rendered, potentially accessing authentication tokens, performing actions on the user's behalf, or exfiltrating data.
What the attacker needed
Vulnerable PDF.js version (<4.2.67); attacker can upload a PDF; victim opens the uploaded PDF
The fix
Upgrade PDF.js to version 4.2.67 or later; if that is not possible, disable dynamic code execution via isEvalSupported, strictly validate FontMatrix as numeric, and sandbox PDF rendering.
How it was found
- Create a PDF whose font definition contains a FontMatrix with a crafted non-numeric last element.
- Upload the PDF to a vulnerable application that renders PDFs with the affected PDF.js version.
- Open the uploaded PDF so the viewer renders it.
- Observe the injected JavaScript executing in the context of the PDF viewer.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
PDF.js is a library that displays PDF files inside web pages. It builds a small piece of JavaScript code to draw text, and it put values from the PDF straight into that code without checking they were numbers. A malicious PDF could therefore smuggle its own JavaScript into the page, which runs when someone opens the file.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.