Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent cross-origin information leakage via range requests #12744

Closed
Rob--W opened this issue Dec 17, 2020 · 8 comments · Fixed by #19028
Closed

Prevent cross-origin information leakage via range requests #12744

Rob--W opened this issue Dec 17, 2020 · 8 comments · Fixed by #19028
Labels

Comments

@Rob--W
Copy link
Member

Rob--W commented Dec 17, 2020

(this is a follow-up to https://phabricator.services.mozilla.com/D91746#3198225)

PDF.js does currently not validate the origin of a PDF response before using it. In web pages, this is not a problem, because unauthorized access is blocked by the same-origin policy. In privileged contexts, such as a browser feature or a browser extension, this can become problematic as soon as it is possible to read content from a PDF file into a web page. Even a unidirectional channel with a binary value (e.g. a boolean yes or no) is enough to read information. With the ongoing work for scripting support (relevant components linked from #12689 (review)), the condition for exploitation is about to be met.

In pages 12 and 13 of https://robwu.nl/s/bugswat2019rw.pdf#page=12, I sketched an attack that abuses Range requests to stitch together responses from different origins to read data across origins, with a proof-of-concept exploit that targeted Chrome / PDFium (CVE-2016-5206).

PDF.js does currently not validate the origins/URLs of responses either - we should do that to prevent a similar attack from happening, at least in the following places:

We should determine the origin of the PDF file (e.g. from the first response) and then verify that the origin is consistent (and otherwise reject the response). xhr.responseURL can be used to obtain the final response URL, after all redirections. If fetch is used, response.url has the same information.

If we are concerned about potentially breaking functionality for users, we can start by adding telemetry to see how often the origin of the initial response differs from the origin of subsequent requests, before we start to enforce the new restriction.

@Snuffleupagus
Copy link
Collaborator

PDF.js does currently not validate the origins/URLs of responses either - we should do that to prevent a similar attack from happening, at least in the following places:

* https://searchfox.org/mozilla-central/rev/de782976bf97669f1e8edee59e7a2398154efe06/toolkit/components/pdfjs/content/PdfJsNetwork.jsm#84-116

* [`src/display/network.js`](https://github.com/mozilla/pdf.js/blob/48e27a1a22a83f1f1be481f992f75f9cee7e5804/src/display/network.js#L84-L107)

Just asking, but shouldn't this include https://github.com/mozilla/pdf.js/blob/master/src/display/fetch_stream.js and https://github.com/mozilla/pdf.js/blob/master/src/display/node_stream.js as well?

@Rob--W
Copy link
Member Author

Rob--W commented Dec 17, 2020

Just asking, but shouldn't this include https://github.com/mozilla/pdf.js/blob/master/src/display/fetch_stream.js and https://github.com/mozilla/pdf.js/blob/master/src/display/node_stream.js as well?

Yes. I didn't enumerate everything, but just some of the examples (hence "at least in the following places").

@brendandahl
Copy link
Contributor

@Rob--W
Copy link
Member Author

Rob--W commented Dec 22, 2020

Disabling redirects is a way to resolve this issue, but only if we are absolutely sure that it is safe to do so.
I like the simplicity, but it is more restrictive than permitting same-origin redirects.

@sylvestre
Copy link
Contributor

If we can disable it and prevent this potential security issue, please disable it and land the patch.

@brendandahl
Copy link
Contributor

Disabling redirects is a way to resolve this issue, but only if we are absolutely sure that it is safe to do so.

Unless I'm missing something, I believe this is how chrome fixed it.

@Rob--W
Copy link
Member Author

Rob--W commented Dec 22, 2020

Disabling redirects is a way to resolve this issue, but only if we are absolutely sure that it is safe to do so.

Unless I'm missing something, I believe this is how chrome fixed it.

That is safe (i.e. not breaking legitimate use cases) IF the PDF resource URL is the final URL. If that is the case, simply blocking redirects can fix this issue.

@Rob--W
Copy link
Member Author

Rob--W commented May 21, 2024

FYI I've also reported this with more details at https://bugzilla.mozilla.org/show_bug.cgi?id=1683940 which was associated with CVE-2021-23953.

This issue was fixed in Firefox, without any code changes in PDF.js because the privileged viewer integration code is fully contained in Firefox's code base.

The Chrome extension (and any other environment without same origin policy) is still vulnerable to this issue.

Rob--W added a commit to Rob--W/pdf.js that referenced this issue Nov 20, 2024
Rob--W added a commit to Rob--W/pdf.js that referenced this issue Nov 20, 2024
Rob--W added a commit to Rob--W/pdf.js that referenced this issue Nov 20, 2024
Rob--W added a commit to Rob--W/pdf.js that referenced this issue Nov 23, 2024
Rob--W added a commit to Rob--W/pdf.js that referenced this issue Nov 23, 2024
Rob--W added a commit to Rob--W/pdf.js that referenced this issue Nov 24, 2024
Rob--W added a commit to Rob--W/pdf.js that referenced this issue Nov 24, 2024
Rob--W added a commit to Rob--W/pdf.js that referenced this issue Nov 24, 2024
Rob--W added a commit to Rob--W/pdf.js that referenced this issue Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants