PDF Viewer will run code from PDF files, missing validation for /Domain and /Range parameters
The PDF viewer's PostScript compiler inserted the Domain and Range array entries from a PDF into generated JavaScript without validating they were numbers, so a malicious PDF could inject JavaScript that runs in the worker. The reporter also describes a path from the worker to the viewer, which could then use the viewer's privileged API and read PDFs from other origins.
Originally disclosed on Mozilla
- Fixed in 8 days
- Paid in 18 days
- Disclosed after 8 days
Created attachment 8965652
Proof of concept PDF
PDF Viewer will convert PostScript calculator functions to JavaScript. While the PostScript code itself is being validated thoroughly, for the Domain and Range parameters in the PDF file the code will only verify that these are arrays (see https://hg.mozilla.org/mozilla-central/file/2f5ffe4fa2153a798ed8b310a597ea92abd1b868/browser/extensions/pdfjs/content/build/pdf.worker.js#l20413). PostScriptCompiler will then insert the array entries into the generated JavaScript code verbatim assuming that these are numbers (as they should be per spec), a malicious PDF file can use strings to inject JavaScript code this way.
Steps to reproduce:
1. Press Ctrl+Shift+J to open Browser Console.
2. Switch back to the browser and open the attached PDF file.
3. Check the Browser Console.
In Firefox 59.0.2 and 61.0a1 (2018-04-06) nightly the following message shows up in Browser Console: "Hello, this is code running in resource://pdf.js/build/pdf.worker.js." You can look at the text of the PDF file to see that the code being executed here is console.log("Hello, this is code running in " + location.href).
I did not implement additional exploit steps but code running in the worker can jump over to the viewer itself. For that it would send a malicious glyph to the viewer, you can see under https://hg.mozilla.org/mozilla-central/file/2f5ffe4fa2153a798ed8b310a597ea92abd1b868/browser/extensions/pdfjs/content/build/pdf.js#l6354 that glyph data is being used to produce JavaScript code without further validation - this code assumes that validation happens in the worker.
Once in the viewer, the code could trigger the ChromeActions API available to the viewer (see https://hg.mozilla.org/mozilla-central/file/2f5ffe4fa2153a798ed8b310a597ea92abd1b868/browser/extensions/pdfjs/content/PdfStreamConverter.jsm#l191) and read/write preferences in the pdfjs.* namespace for example. Also, it could add iframe tags pointing to other PDF files (e.g. from intranet domains). Since PDF Viewer would load into these domains as well, it could access their contents (same-origin) and steal PDF data.
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
The Domain and Range parameters were only checked to be arrays, not that their entries were numbers, before being inserted verbatim into generated JavaScript.
Impact
Code runs in the PDF worker, and the reporter suggests it could reach the viewer to use its privileged API and read PDFs from other origins, though those extra steps were not implemented.
What the attacker needed
Victim opens a malicious PDF; PDF viewer uses PostScript calculator functions
How it was found
- Open the Browser Console.
- Switch back to the browser and open the attached PDF file.
- Check the Browser Console for the injected message.
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.
A PDF can contain small programs that the viewer translates into JavaScript. The viewer checked the program itself but trusted two lists of numbers without checking their contents, so a crafted PDF could slip its own code into the generated script. That code then runs inside the browser's PDF component.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.