PDF.js vulnerable to CSS injection, leads to exfiltrating saved signatures
Firefox's built-in PDF viewer allows a CSS injection via a Link header, enabling an attacker to exfiltrate saved signatures by using CSS attribute selectors. An attacker could convince a user to open the signatures menu and then extract the SVG path of the signature.
Originally disclosed on Mozilla
- Fixed in 18 days
- Paid in 36 days
- Disclosed after 18 days
Created attachment 9533505 demo_minimal.png
Description
Firefox's built-in PDF viewer allows users to create and save signatures. By abusing a CSS injection, it is possible for any website to exfiltrate said signatures. This works even in private browsing mode, as saved signatures appear there too.
The CSS injection can be performed by serving a PDF file from an attacker-controlled website with a Link header to load arbitrary CSS into the PDF viewer. If the user can be convinced to open up the signatures menu (e.g. hold down the Enter key or make a single click on the attacker's website), the CSS attribute selectors can be used to exfiltrate the SVG path of a signature.
This CSS injection can be used for other attacks as well, but I found the signature exfiltration to be the most impactful one.
Repro
There are two repros, one very minimal one for testing, and a more advanced one for exfiltrating a signature.
You will need python3 and Flask installed for both repros.
Minimal
The minimal repro just serves a small PDF file with the following header: Link: <data:text/css,*{rotate:180deg;background:%23F002}>; rel=stylesheet.
To use it, run pdf_css_injection_minimal.py and visit http://127.0.0.1:8000/. You should see all of the UI elements upside down and red.
See demo_minimal.png for an example of what it should look like.
Signature exfil
While this repro works cross-platform, the timings are configured to work best on Windows 10.
Make sure you have at least one signature saved - if not, open any PDF file and create one. Then, run pdf_css_injection_demo.py, visit http://127.0.0.1:8000/, and hold Enter for a couple seconds. The exfiltration will begin and you should see the saved signature slowly appear on the page.
The signature exfiltration repro does a lot behind the scenes:
- Loads a PDF into an iframe with a lot of Link headers set.
- The first Link header loads CSS to help with opening the signatures menu.
- The rest of the Link headers are behind a media query to load them later on.
- Waits for the iframe to load, focuses it, and uses a hash fragment to force select the signatures menu.
- Since the user is holding Enter, the signatures menu will pop open. It cannot close due to the CSS loaded earlier.
- Shrinks the iframe to force the rest of the Link headers to load.
- The reason for this is to prevent the Link headers from blocking the page from loading.
- Repeatedly exfiltrates the
dattribute on the SVG path of the signature by 4 digit groups. - Displays the exfiltrated data and SVG path on the page.
I am 100% sure this attack could be made significantly more reliable and way faster, this here is just a proof of concept I quickly threw together.
See demo_exfil.mp4 for an example of what this repro should look like.
Fix
My suggested fix would be ignoring the Link header for the built-in PDF viewer. CSP might also help, though I'm not sure if that'd be possible to implement.
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 the PDF viewer does not sanitise or restrict Link headers, allowing arbitrary CSS to be loaded and used to exfiltrate data via attribute selectors.
Impact
An attacker could exfiltrate saved signatures from Firefox's PDF viewer, even in private browsing mode, if the user is convinced to open the signatures menu.
What the attacker needed
Victim uses Firefox PDF viewer; victim has saved signature; victim opens attacker's PDF; victim holds Enter or clicks
The fix
The suggested fix is to ignore the Link header for the built-in PDF viewer; CSP might also help but may not be possible.
How it was found
- Serve a PDF with a Link header that loads CSS to rotate and colour the UI.
- Load the PDF in an iframe with additional Link headers behind a media query.
- Focus the iframe and use a hash fragment to select the signatures menu while the user holds Enter.
- Shrink the iframe to trigger the remaining Link headers to load.
- Repeatedly exfiltrate the d attribute of the signature's SVG path in 4-digit groups.
- Display the exfiltrated data on the page.
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 CSS injection lets an attacker add their own style rules to a web page. Here, the PDF viewer in Firefox loads a stylesheet from a Link header, and those styles can read parts of the page and send them to the attacker. The attacker tricks the user into opening the signatures menu, then uses CSS to slowly copy the signature's shape data.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.