In ESR52, range-based requests in pdf.js (which allows pdfs to render-as-load) go out on the default circuit as the relevant code was running in the System security context. To 'fix' the issue, we simply disabled range-based request with the 'pdfjs.disableRange' option. However, in ESR60 based Tor Browser, enabling this option prevents PDFs from loading at all. Without the option enabled, PDFs load and render, but the range-based requests still go out on the default circuit.
Well, flipping that preference has been an experiment. And I am not convinced yet that the usability impact was worth it. Thus, I wonder if we should just abandon this "fix" idea and try to look again in a new ticket at dealing with the original linkability concern? Maybe ESR60 makes it easier now to isolate those range requests properly? What do you think?
Well, flipping that preference has been an experiment. And I am not convinced yet that the usability impact was worth it. Thus, I wonder if we should just abandon this "fix" idea and try to look again in a new ticket at dealing with the original linkability concern? Maybe ESR60 makes it easier now to isolate those range requests properly? What do you think?
Yeah I'm inclined to agree. For the time being, I'm investigating whether we can enable FPI for these range requests .
Two patches, one for tor-browser and one for torbutton.
The patches take an approach of 'smuggling' the first party domain on the existing nsIPrivateBrowsingChannel used by XMLHttpRequest. Basically, the first-party domain is known when the range-based request is created, but since it's created from within chrome js code, it gets the System Principal which throws out all that info. So, in pdfjs we set the firstPartyDomain on the channel object which is then read by torbutton. If torbutton fails to find a firstPartyDomain in the usual way from the OriginAttributes, it will try to read it off of the channel directly.
With this smuggling hack in place, we should be able to fix any other 'XMLHttpRequest-created-in-System-Principal' first-party isolation issues we come across.
Currently doing an RBM build with the patches applied just to make sure it all works as expected without hacks.
EDIT: Looks like this patch only works when browser.tabs.remote.autostart is false (disables the separate content process). Will have to dig into this and find the other XMLHttpRequest constructors in pdfjs which shouldn't be to tricky.
Trac: Status: needs_information to needs_review Keywords: TorBrowserTeam201807 deleted, TorBrowserTeam201807R added
So this updated patch shows the general approach here of smuggling the first-party domain on the channel object directly as a fallback in case the domain stored on the origin attributes is empty-string (as is the case for XMLHttpRequests made under the System Principal.
I think the final patch (assuming y'all are ok with this approach) would stow the smuggled first-party domain on the nsIHttpChannel, rather than the nsIPrivateBrowsingChannel (since almost everything implements the private browsing interface, but we only need it on the http channel).
Neat idea! I am fine doing this hack if that helps us. Note, we want to have domain isolation working even if the user is not in PBM as PBM is only used to take care of disk leaks. The pref governing the domain isolation is privacy.firstparty.isolate.
It might be worth as well to open a Mozilla bug, blocking the FirstPartyIsolation one (https://bugzilla.mozilla.org/show_bug.cgi?id=1299996) and asking Mozilla for feedback wrt the final approach you come up with.
FWIW: We got reports on the blog that disableRange is still enabled in the alpha series after updating from 8.0a8. I guess the pref we flipped is kept because it is essentially a user set pref. I think we should try to get that solved as part of this patch: on the alpha series we should try to (re)set the behavior we want again.
returning the document's firstPartyDomain, as needed in torbutton domain isolator. With this approach (assuming it works) we wouldn't need to alter channel classes in Firefox or patch torbutton.
Ok, so in PdfStreamConverter.jsm there are two places where channels are created: PdfStreamConverter::onStartRequest (which seems to load the pdf.js viewer itself: "re/pdf.js/web/viewer.html")) and ChromeActions::download which appears to be dead code; breakpoints placed there never get hit and no call to 'download' function seems to exist in the source, but it's JavaScript so who knows what fancy bs it's pulling.
The range-based requests occur via an XMLHttpRequest whose channel is created internally in one of the constructors/factory methods in the C++ source, so we don't seem to have access to it at construction and it can't be replaced with our own channel with the correct principal set.
HOWEVER!
It seems that while we cannot simply overwrite the channel's originAttribute's firstpartyDomain and have it stick, we can simply overwrite the channel's entire originAttributes. I've prototyped doing so in the debugger and it would seem that everything works as expected. I'll get a patch written and tested tomorrow and let y'all know how it goes.
(11/01/2018 03:47:14 PM) arthuredelstein: hi! your new patch for #26540 (moved) looks good! I'm wondering though, about cache and cookies and things like that.
(11/01/2018 03:47:25 PM) arthuredelstein: Does setting the originAttributes on loadinfo take care of all of that?
(11/01/2018 03:47:41 PM) arthuredelstein: (I guess the range request pieces might not be cached, not sure.)
(11/01/2018 03:47:54 PM) arthuredelstein: But, for example, if there's a cookie header, does that get stored in the right place?
(11/01/2018 03:48:02 PM) arthuredelstein: I don't know how to easily test that.
The origin attributes are set immediately after channel creation, FPI regarding cookies is now enforced correctly, and pdfjs's range-based requests now go out on the correct channel (the channel for the hosted pdf's domain if entered directly in the title bar, and the first party domain's when embedded via an iframe or embed node).
Oh, and while you are at it: while testing your patch I got tons (i.e. hundreds) of
Attempting to post a message to window with url"re[/pdf.js/web/viewer.html"](/pdf.js/web/viewer.html") and origin"re[/pdf.js^firstPartyDomain=amnestyusa.org"](/pdf.js^firstPartyDomain=amnestyusa.org") from a system principalscope with mismatched origin "[System Principal]"
messages in my browser console. Those are not related to your patch, but could you file a FPI bug blocking the above one as well (or maybe the FirstPartyIsolationQA bug, I am not sure)? I have not checked whether those messages are actually a sign of something that is deeper wrong or whether it's just console spam.
Trac: Status: needs_review to closed Resolution: N/Ato fixed
Oh, and while you are at it: while testing your patch I got tons (i.e. hundreds) of
{{{
Attempting to post a message to window with url
"re/pdf.js/web/viewer.html" and origin
"re/pdf.js^firstPartyDomain=amnestyusa.org" from a system principal
scope with mismatched origin "[System Principal]"
}}}
messages in my browser console. Those are not related to your patch, but could you file a FPI bug blocking the above one as well (or maybe the FirstPartyIsolationQA bug, I am not sure)? I have not checked whether those messages are actually a sign of something that is deeper wrong or whether it's just console spam.