Skip to content

Commit

Permalink
fix: interop with Brave Shields rules (#976)
Browse files Browse the repository at this point in the history
Closes #962
  • Loading branch information
lidel authored Jan 29, 2021
1 parent 991f7e8 commit 9ffe71c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions add-on/src/lib/ipfs-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,13 @@ function isSafeToRedirect (request, runtime) {
}
}
}
// Ignore requests for which redirect would fail due to Brave Shields rules
// https://github.com/ipfs-shipyard/ipfs-companion/issues/962
if (runtime.brave && request.type !== 'main_frame') {
// log('Skippping redirect of IPFS subresource due to Brave Shields', request)
return false
}

return true
}

Expand Down
29 changes: 29 additions & 0 deletions test/functional/lib/ipfs-request-workarounds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,35 @@ describe('modifyRequest processing', function () {
})
})

// https://github.com/ipfs-shipyard/ipfs-companion/issues/962
describe('redirect of IPFS resource to local gateway in Brave', function () {
it('should be redirected if not a subresource (not impacted by Brave Shields)', function () {
runtime.isFirefox = false
runtime.brave = { thisIsFakeBraveRuntime: true }
const request = {
method: 'GET',
type: 'image',
url: 'https://ipfs.io/ipfs/bafkqaaa',
initiator: 'https://some-website.example.com' // Brave (built on Chromium)
}
expect(modifyRequest.onBeforeRequest(request))
.to.equal(undefined)
})
it('should be left untouched if subresource (would be blocked by Brave Shields)', function () {
runtime.isFirefox = false
runtime.brave = { thisIsFakeBraveRuntime: true }
const cid = 'bafkqaaa'
const request = {
method: 'GET',
type: 'main_frame',
url: `https://ipfs.io/ipfs/${cid}`,
initiator: 'https://some-website.example.com' // Brave (built on Chromium)
}
expect(modifyRequest.onBeforeRequest(request).redirectUrl)
.to.equal(`http://localhost:8080/ipfs/${cid}`)
})
})

after(function () {
delete global.URL
delete global.browser
Expand Down

0 comments on commit 9ffe71c

Please sign in to comment.