-
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
Restore gateway redirect for CORS XHRs in Firefox #511
Conversation
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.
💯 bonus points to @lidel for the issue report on bugzilla with minimal working extension to demonstrate the issue, and art lolz in the PR. |
add-on/src/lib/ipfs-request.js
Outdated
@@ -65,7 +68,7 @@ function createRequestModifier (getState, dnsLink, ipfsPathValidator, runtime) { | |||
if (request.url.includes('/api/v0/add')) { | |||
for (let header of request.requestHeaders) { | |||
if (header.name === 'Connection') { | |||
console.log('[ipfs-companion] Executing "Connection: close" workaround for https://github.com/ipfs/go-ipfs/issues/5168') | |||
console.warn('[ipfs-companion] Executing "Connection: close" workaround for go-ipfs/issues/5168') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: logs with urls in are great, let's keep it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
Dnslink lookup is disabled by default, but if user opted-in to it, many websites were broken due to invalid gateway redirects. This change fixes regression introduced by: #511 and adds tests to guard against the problem in future.
Dnslink lookup is disabled by default, but if user opted-in to it, many websites were broken due to invalid gateway redirects. This change fixes regression introduced by: #511 and adds tests to guard against the problem in future.
Dnslink lookup is disabled by default, but if user opted-in to it, many websites were broken due to invalid gateway redirects. This change fixes regression introduced by: #511 and adds tests to guard against the problem in future.
Dnslink lookup is disabled by default, but if user opted-in to it, many websites were broken due to invalid gateway redirects. This change fixes regression introduced by: #511 and adds tests to guard against the problem in future.
Dnslink lookup is disabled by default, but if user opted-in in latest version websites were broken due to false-positive late gateway redirects of XHR requests. This PR fixes dnslink regression introduced by #511 and adds tests to guard against the problem in future. Some deeper refactoring is due, but that is something for separate PR. I want to land this PR as soon as possible, so that dnslink works again.
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.
In short,
onBeforeRequest
can't redirect anything when CORS XHR is processed, otherwise it will trigger false-positive CORS error. Good news is thatonHeadersReceived
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 is addressed.
Additional Notes:
I raised privacy concerns in the upstream bug.
Developers look for an efficient workaround in WebExtension API
Jean-François Millet, 1857, Oil on canvas