Skip to content
XSS Disclosed report Intermediate

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

  1. Craft a Malicious PDF: Create a PDF file that includes a manipulated FontMatrix array with a string payload.

    Example FontMatrix:

    /FontMatrix [1 2 3 4 5 (0\); alert\('foobar')]
    

poc.pdf

  1. Upload the PDF to the Target Application: go to https://gitlab.com/ and upload the poc.pdf file in the repo
  2. 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

poc.pdf

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.

The original report as published on GitLab. Images and videos are our own copies; raw HTML is shown as text. View it on GitLab.

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

  1. Create a PDF file with a manipulated FontMatrix array containing a string payload.
  2. Upload the PDF to the target application (e.g., a GitLab repository).
  3. 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.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.