Skip to content
XSS Write-up Intermediate

Stored XSS in PDF Viewer

The application used a vulnerable version of PDF.js (CVE-2024-4367) to render uploaded PDFs, allowing JavaScript execution in the context of the hosting domain. An attacker could upload a malicious PDF that, when viewed, executes script to access cookies, local storage, and the DOM, bypassing the site's CSP.

Osama Avvan Follow

Published on medium.com

During a Recent Web App Penetest, I came across a File Upload functionality that only accepts PDF and Image files and allows the preview of the PDF file in a PDF viewer.

Osama Avvan, on medium.com

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

Impact

An attacker could execute arbitrary JavaScript in the context of the hosting domain, potentially stealing cookies, local storage, or JWT tokens, and bypassing the site's CSP.

What the attacker needed

File upload functionality accepting PDFs; Application uses vulnerable PDF.js; Victim views the uploaded PDF

The fix

The application should update PDF.js to a version that is not vulnerable to CVE-2024-4367.

How it was found

  1. Download and run the exploit script from the provided GitHub repository.
  2. Generate a malicious PDF using the script with a JavaScript payload.
  3. Upload the generated PDF to the web application's file upload functionality.
  4. View the uploaded PDF in the application's PDF viewer.
  5. Observe the JavaScript execution (e.g., an alert showing the domain name).

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 displays PDF files in a web browser. A bug in this tool let a malicious PDF run its own code as if it were part of the website. That meant an attacker could steal information like login tokens from anyone who opened the PDF.

What is XSS?

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

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.