question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prevent cross-origin information leakage via range requests

See original GitHub issue

(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 https://github.com/mozilla/pdf.js/pull/12689#pullrequestreview-549350284), 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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Rob--Wcommented, 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”).

0reactions
Rob--Wcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deep dive in CORS: History, how it works, and best practices
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at ... Leaking info to 3rd parties.
Read more >
Cross-Origin Read Blocking (CORB)
This document outlines Cross-Origin Read Blocking, an algorithm by which some dubious cross-origin resource loads may be identified and blocked by web browsers ......
Read more >
What are CORS Attacks and How can you Prevent them?
Cross-origin resource sharing (CORS) attacks are made possible through web server misconfigurations. In this article, we'll look at what ...
Read more >
How to win at CORS - JakeArchibald.com
If a resource contains private data when it's requested with cookies, but you only want to expose the without-cookies data, then it's best...
Read more >
1260649 - Leaking size of cross-origin resources by using ...
When a cross-origin resource is used in an audio/video tag, a request containing the Range header asking for "bytes=0-" is issued. If the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found