-
Notifications
You must be signed in to change notification settings - Fork 325
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
gateway redirect messes up CORS headers on firefox #436
Comments
It seems to be a bug in Firefox (see findings below). I filled an upstream bug: Steps to ReproduceI created a minimal PoC extension to confirm that the problem is not companion-specific: ipfs-companion-cors-issue-436-mvp.zip
Chrome: Success, No ErrorBoth buttons result in a successful fetch and Firefox: CORS ErrorOnly the first button results in a successful fetch, second button triggers CORS error. |
Note to self: for the same bogus reason Firefox prevents Pannellum from using IPFS-hosted images (rerouted by IPFS Companion) as WebGL textures. |
|
Due to discrepancy between how Chrome and Firefox handle CORS validation in To mitigate the situation, I decided to disable redirect for cross-origin XHRs that would fail anyway, restoring original functionality to websites impacted by this issue. See PR #494 – it is an interesting edge case, so feedback would be appreciated. |
This PR disables gateway redirect for cross-origin XHRs. - It fixes all the websites broken by [CORS false-positive bug in Firefox](#436 (comment)) - It is a "lesser evil". There will be no gateway redirect for such requests, but at least "IPFS-enabled" websites that do cross-origin requests to different gateways will work. - The full context is in #436 (comment) including a link to the upstream bug.
Merged Firefox-only workaround from #494 and released it to beta channel as v2.3.0.9590 and stable as v2.3.1. Let's keep this issue open until https://bugzilla.mozilla.org/show_bug.cgi?id=1450965 is closed. |
Context for CORS XHR problems in Firefox: #436 In short, onBeforeRequest should not change anything, as it will trigger false-positive CORS error. onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late. This is not ideal, as there is an outgoing request to the public gateway, and we need to read response headers before connection is aborted, but we can't do better than that until https://bugzilla.mozilla.org/show_bug.cgi?id=1450965 is resolved.
To restore feature parity between browsers, I decided to enable gateway redirect for CORS XHRs in Firefox using late redirects at a price of small overhead. Details in PR #511. |
This PR restores gateway redirect for CORS XHR in Firefox via late redirect in `onHeadersReceived` and closes #436. Context for why CORS XHR were not redirected until now can be found in #436 (comment) and upstream [Bug #1450965](https://bugzilla.mozilla.org/show_bug.cgi?id=1450965). In short, `onBeforeRequest` can't redirect anything when CORS XHR is processed, otherwise it will trigger false-positive CORS error. Good news is that `onHeadersReceived` is executed long after CORS validation happens in Firefox, and allows us to cancel original connection and do a late redirect right after response headers arrive. This is the best we can do until upstream [Bug #1450965](https://bugzilla.mozilla.org/show_bug.cgi?id=1450965) is addressed. Additional Notes: - The original outgoing request to the public gateway has to happen :( I [raised privacy concerns](https://bugzilla.mozilla.org/show_bug.cgi?id=1450965#c4) in the upstream bug. - Good news is that we only need to read response headers before connection is aborted. The overhead is minimal and I believe it is worth it: enables us to reach feature-parity with Chrome and removes dapp developer confusion that was caused by different redirect behaviors in Firefox and Chrome.
Merged #511 and released to beta channel as v2.4.0.10190. |
According to https://bugzilla.mozilla.org/show_bug.cgi?id=1450965#c33 the bug will be fixed in Firefox 69. I am reopening this, so we don't forget to remove workaround introduced in #511 when FF69 lands to the stable channel in September (2019-09-03 according to this page) |
Firefox 69 is released. |
This change removes woraround introduced in PR #494 and restores redirect in onBeforeRequest. The original bug was fixed in Firefox 69, that is why we also bump minimal version. More info at: #436 (comment)
This change removes woraround introduced in PR #494 and restores redirect in onBeforeRequest. The original bug was fixed in Firefox 69, that is why we also bump minimal version. More info at: #436 (comment)
This change removes workaround introduced in PR #494 and restores redirect in onBeforeRequest. The original bug was fixed in Firefox 69, that is why we also bump minimal version. More info at: #436 (comment)
Browser:
Firefox 59.0.2
AddOn Version:
IPFS Companion (RC1@fb21b6d) 2.2.0.8540
orIPFS Companion 2.1.0
Given this webpage:
when clicking on the public gateway button firefox will cancel the request and issue a same-origin-policy warning due to missing CORS headers even though the local gateway has the necessary CORS-headers set which can be checked clicking the other button (be sure to check which origin you are accessing the document when using the IPFS link).
I checked Chrome 65 for comparison and the issue isn't present.
The text was updated successfully, but these errors were encountered: