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: interop with Brave Shields rules #976

Merged
merged 1 commit into from
Jan 29, 2021
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
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