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.
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.
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
- Download and run the exploit script from the provided GitHub repository.
- Generate a malicious PDF using the script with a JavaScript payload.
- Upload the generated PDF to the web application's file upload functionality.
- View the uploaded PDF in the application's PDF viewer.
- 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.