Skip to content

Commit

Permalink
fix: CORS false-positive in Chrome 71 (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Nov 8, 2018
1 parent 7a6fac1 commit 01e72f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
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

0 comments on commit 01e72f2

Please sign in to comment.