Stored XSS via PDFjs
A flaw in PDF.js glyph rendering allows a malicious PDF with a crafted FontMatrix array to execute arbitrary JavaScript when opened. An attacker could run code in the context of the PDF viewer, potentially leading to data exposure or cross-site scripting in web applications.
GitLab
Originally disclosed on GitLab
- Fixed in 16 days
- Disclosed after 16 days
⚠️ Please read the process on how to fix security issues before starting to work on the issue. Vulnerabilities must be fixed in a security mirror.
HackerOne report #2512938 by h4x0r_dz on 2024-05-20:
Report | Attachments | How To Reproduce
Summary
I Found CVE-2024-4367, a vulnerability in PDF.js, a JavaScript-based PDF viewer maintained by Mozilla. This vulnerability allows an attacker to execute arbitrary JavaScript code when a malicious PDF file is opened. Given that PDF.js is widely used in web applications and integrated into Firefox as its default PDF viewer, the impact of this vulnerability is significant.
Affected Versions
- PDF.js versions used by Firefox < 126
- All web and Electron applications using vulnerable versions of PDF.js (pdfjs-dist Node module)
Vulnerability Details
CVE-2024-4367 occurs due to a flaw in the glyph rendering process within PDF.js. Specifically, the issue arises when a JavaScript Function object is created to optimize glyph rendering by pre-compiling path generation instructions. This process improperly handles the FontMatrix array, allowing for arbitrary code injection.
Steps to Reproduce
-
Craft a Malicious PDF: Create a PDF file that includes a manipulated
FontMatrixarray with a string payload.Example
FontMatrix:/FontMatrix [1 2 3 4 5 (0\); alert\('foobar')]
- Upload the PDF to the Target Application: go to https://gitlab.com/ and upload the poc.pdf file in the repo
- Open the PDF in the Application: Once the PDF is opened, the injected JavaScript code (
alert('foobar')) will be executed.
Proof of Concept (PoC)
Recommendations
Attachments:
- PoC PDF File
Impact
Impact
Exploiting this vulnerability allows arbitrary JavaScript execution with the following potential impacts:
- User Data Exposure: The attacker can access sensitive information within the context of the PDF viewer.
- Cross-Site Scripting (XSS): When integrated into web applications, this can lead to XSS attacks, compromising user accounts and data.
- Native Code Execution in Electron Apps: In Electron applications that do not properly sandbox JavaScript, this can lead to full native code execution.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, PDF.js improperly handles the FontMatrix array when creating a JavaScript Function for glyph rendering, allowing code injection.
Impact
An attacker could execute arbitrary JavaScript in the PDF viewer context, potentially exposing user data or enabling cross-site scripting in web applications; in Electron apps without proper sandboxing, this could lead to native code execution.
What the attacker needed
Victim opens a malicious PDF; PDF.js used in the application
How it was found
- Create a PDF file with a manipulated FontMatrix array containing a string payload.
- Upload the PDF to the target application (e.g., a GitLab repository).
- Open the PDF in the application, which triggers execution of the injected JavaScript.
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 report has not been written yet. The Original tab links to the source.
PDF.js is a tool that lets web browsers display PDF files. A bug in how it draws text allowed a specially made PDF to run JavaScript code when opened, which could let an attacker do things like steal information or take over an account.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.