Skip to content

Commit 9ffe71c

Browse files
authored
fix: interop with Brave Shields rules (#976)
Closes #962
1 parent 991f7e8 commit 9ffe71c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

add-on/src/lib/ipfs-request.js

+7
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,13 @@ function isSafeToRedirect (request, runtime) {
530530
}
531531
}
532532
}
533+
// Ignore requests for which redirect would fail due to Brave Shields rules
534+
// https://github.com/ipfs-shipyard/ipfs-companion/issues/962
535+
if (runtime.brave && request.type !== 'main_frame') {
536+
// log('Skippping redirect of IPFS subresource due to Brave Shields', request)
537+
return false
538+
}
539+
533540
return true
534541
}
535542

test/functional/lib/ipfs-request-workarounds.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,35 @@ describe('modifyRequest processing', function () {
322322
})
323323
})
324324

325+
// https://github.com/ipfs-shipyard/ipfs-companion/issues/962
326+
describe('redirect of IPFS resource to local gateway in Brave', function () {
327+
it('should be redirected if not a subresource (not impacted by Brave Shields)', function () {
328+
runtime.isFirefox = false
329+
runtime.brave = { thisIsFakeBraveRuntime: true }
330+
const request = {
331+
method: 'GET',
332+
type: 'image',
333+
url: 'https://ipfs.io/ipfs/bafkqaaa',
334+
initiator: 'https://some-website.example.com' // Brave (built on Chromium)
335+
}
336+
expect(modifyRequest.onBeforeRequest(request))
337+
.to.equal(undefined)
338+
})
339+
it('should be left untouched if subresource (would be blocked by Brave Shields)', function () {
340+
runtime.isFirefox = false
341+
runtime.brave = { thisIsFakeBraveRuntime: true }
342+
const cid = 'bafkqaaa'
343+
const request = {
344+
method: 'GET',
345+
type: 'main_frame',
346+
url: `https://ipfs.io/ipfs/${cid}`,
347+
initiator: 'https://some-website.example.com' // Brave (built on Chromium)
348+
}
349+
expect(modifyRequest.onBeforeRequest(request).redirectUrl)
350+
.to.equal(`http://localhost:8080/ipfs/${cid}`)
351+
})
352+
})
353+
325354
after(function () {
326355
delete global.URL
327356
delete global.browser

0 commit comments

Comments
 (0)