"CVE-2024-4367 – Arbitrary JavaScript execution in PDF.js" by CodeanLabs
PDF.js compiled glyph rendering commands into a JavaScript Function without properly sanitising the font matrix, allowing an attacker to inject arbitrary JavaScript code via a malicious PDF. This code executes when the PDF is opened, potentially leading to cross-site scripting or native code execution in affected applications.
Published on codeanlabs.com
This post details CVE-2024-4367, a vulnerability in PDF.js found by Codean Labs. PDF.js is a JavaScript-based PDF viewer maintained by Mozilla.
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 font matrix array from a PDF was inserted directly into a dynamically generated JavaScript function without proper validation, allowing arbitrary code injection.
Impact
An attacker could execute arbitrary JavaScript in the context of the PDF viewer, potentially leading to data leaks, malicious actions, or full account takeover; in Electron apps without proper sandboxing, this could even lead to native code execution.
What the attacker needed
Victim opens a malicious PDF; PDF.js version before 4.2.67; no strict CSP blocking eval
The fix
The vulnerability was fixed in PDF.js version 4.2.67 and later; as a workaround, setting `isEvalSupported` to false or using a strict CSP that disables `eval` and `Function` also mitigates the issue.
How it was found
- Create a PDF with a Type1 font that has no internal FontMatrix definition.
- In the PDF's font dictionary, set a custom FontMatrix array containing a string value with JavaScript code.
- Open the PDF in a vulnerable PDF.js viewer, which compiles the glyph rendering commands into a Function object.
- The injected JavaScript code executes when the glyph is rendered.
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 tool that lets you view PDF files in your web browser. The bug meant that a specially crafted PDF file could run harmful code on your computer when you opened it, because the tool didn't check some input properly. This could let an attacker steal information or take control of your account.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.