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

fix: CORS false-positive in Chrome 71 #616

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions add-on/src/lib/ipfs-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru
onBeforeSendHeaders (request) {
const state = getState()

// Skip if IPFS integrations are inactive or request is marked as ignored
if (!state.active || isIgnored(request.requestId)) {
// Skip if IPFS integrations are inactive
if (!state.active) {
return
}

Expand Down Expand Up @@ -150,10 +150,9 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru
request.requestHeaders.push(expectHeader)
}
}
// For some reason js-ipfs-api sent requests with "Origin: null" under Chrome
// which produced '403 - Forbidden' error.
// For some reason js-ipfs-api sends requests with "Origin: null" under Chrome
// which produces '403 - Forbidden' error.
// This workaround removes bogus header from API requests
// TODO: check if still necessary
for (let i = 0; i < request.requestHeaders.length; i++) {
let header = request.requestHeaders[i]
if (header.name === 'Origin' && (header.value == null || header.value === 'null')) {
Expand Down
2 changes: 2 additions & 0 deletions test/functional/lib/ipfs-request-workarounds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('modifyRequest processing', function () {
type: 'xmlhttprequest',
url: `${state.apiURLString}api/v0/add?progress=true&wrapWithDirectory=true&pin=true&wrap-with-directory=true&stream-channels=true`
}
modifyRequest.onBeforeRequest(request) // executes before onBeforeSendHeaders, may mutate state
expect(modifyRequest.onBeforeSendHeaders(request).requestHeaders).to.deep.include(expectHeader)
})
})
Expand All @@ -52,6 +53,7 @@ describe('modifyRequest processing', function () {
type: 'xmlhttprequest',
url: `${state.apiURLString}api/v0/id`
}
modifyRequest.onBeforeRequest(request) // executes before onBeforeSendHeaders, may mutate state
expect(modifyRequest.onBeforeSendHeaders(request).requestHeaders).to.not.include(bogusOriginHeader)
})
})
Expand Down