Skip to content

Commit 458bf34

Browse files
authored
fix: disable redirect for CID-in-subdomain (#617)
This is a fix of a regression for #537 that was introduced when X-Ipfs-Path header support was added. Until we are able to provide the same origin-based security guarantees at a local gateway, we should not redirect resources that use cid-in-subdomain deployment, as it is a strong hint they care about Origin-based isolation and we should not relax those guarantees.
1 parent f008b09 commit 458bf34

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ function isSafeToRedirect (request, runtime) {
306306
return false
307307
}
308308

309+
// For now we do not redirect if cid-in-subdomain is used
310+
// as it would break origin-based security perimeter
311+
if (IsIpfs.subdomain(request.url)) {
312+
return false
313+
}
314+
309315
// Ignore XHR requests for which redirect would fail due to CORS bug in Firefox
310316
// See: https://github.com/ipfs-shipyard/ipfs-companion/issues/436
311317
// TODO: revisit when upstream bug is addressed

test/functional/lib/ipfs-request-gateway-redirect.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,13 @@ describe('modifyRequest.onBeforeRequest:', function () {
268268
it('should be left untouched for IPFS', function () {
269269
state.redirect = true
270270
const request = url2request('http://bafybeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge.ipfs.dweb.link/')
271+
request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ' }]
271272
expectNoRedirect(modifyRequest, request)
272273
})
273274
it('should be left untouched for IPNS', function () {
274275
state.redirect = true
275276
const request = url2request('http://bafybeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge.ipns.dweb.link/')
277+
request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ' }]
276278
expectNoRedirect(modifyRequest, request)
277279
})
278280
})

0 commit comments

Comments
 (0)