Skip to content

Commit c3f4c53

Browse files
authored
fix: ipfs:// in Firefox incognito window (#835)
The new routing page will detect when CID is valid and will redirect to public gateways at `.dweb.link`
1 parent 3c8c57d commit c3f4c53

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

add-on/manifest.firefox.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@
2323
{
2424
"protocol": "web+dweb",
2525
"name": "IPFS Companion: DWEB Protocol Handler",
26-
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
26+
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
2727
},
2828
{
2929
"protocol": "web+ipns",
3030
"name": "IPFS Companion: IPNS Protocol Handler",
31-
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
31+
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
3232
},
3333
{
3434
"protocol": "web+ipfs",
3535
"name": "IPFS Companion: IPFS Protocol Handler",
36-
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
36+
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
3737
},
3838
{
3939
"protocol": "dweb",
4040
"name": "IPFS Companion: DWEB Protocol Handler",
41-
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
41+
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
4242
},
4343
{
4444
"protocol": "ipns",
4545
"name": "IPFS Companion: IPNS Protocol Handler",
46-
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
46+
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
4747
},
4848
{
4949
"protocol": "ipfs",
5050
"name": "IPFS Companion: IPFS Protocol Handler",
51-
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
51+
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
5252
}
5353
]
5454
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ function isSafeToRedirect (request, runtime) {
512512

513513
// This is just a placeholder that we had to provide -- removed in normalizedRedirectingProtocolRequest()
514514
// It has to match URL from manifest.json/protocol_handlers
515-
const redirectingProtocolEndpoint = 'https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#'
515+
const redirectingProtocolEndpoint = 'https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#'
516516

517517
function redirectingProtocolRequest (request) {
518518
return request.url.startsWith(redirectingProtocolEndpoint)

test/functional/lib/ipfs-request-protocol-handlers.test.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -59,81 +59,81 @@ describe('modifyRequest.onBeforeRequest:', function () {
5959

6060
// without web+ prefix (Firefox > 59: https://github.com/ipfs-shipyard/ipfs-companion/issues/164#issuecomment-356301174)
6161
it('should not be normalized if ipfs:/{CID}', function () {
62-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
62+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
6363
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
6464
})
6565
it('should be normalized if ipfs://{CID}', function () {
66-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
66+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
6767
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest')
6868
})
6969
it('should not be normalized if ipns:/{fqdn}', function () {
70-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#ipns%3A%2Fipfs.io%3FargTest%23hashTest')
70+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#ipns%3A%2Fipfs.io%3FargTest%23hashTest')
7171
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
7272
})
7373
it('should be normalized if ipns://{fqdn}', function () {
74-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#ipns%3A%2F%2Fipfs.io%3FargTest%23hashTest')
74+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#ipns%3A%2F%2Fipfs.io%3FargTest%23hashTest')
7575
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest')
7676
})
7777
it('should be normalized if ipfs://{fqdn}', function () {
78-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#ipfs%3A%2F%2Fipfs.io%3FargTest%23hashTest')
78+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#ipfs%3A%2F%2Fipfs.io%3FargTest%23hashTest')
7979
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest')
8080
})
8181
it('should be normalized if dweb:/ipfs/{CID}', function () {
82-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#dweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
82+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#dweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
8383
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest')
8484
})
8585
it('should not be normalized if dweb://ipfs/{CID}', function () {
86-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#dweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
86+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#dweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
8787
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
8888
})
8989
it('should be normalized if dweb:/ipns/{foo}', function () {
90-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#dweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest')
90+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#dweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest')
9191
expect(modifyRequest.onBeforeRequest(request).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest')
9292
})
9393
it('should not be normalized if dweb://ipns/{foo}', function () {
94-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#dweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest')
94+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#dweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest')
9595
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
9696
})
9797

9898
// web+ prefixed versions (Firefox < 59 and Chrome)
9999
it('should not be normalized if web+ipfs:/{CID}', function () {
100-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
100+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
101101
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
102102
})
103103
it('should be normalized if web+ipfs://{CID}', function () {
104-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
104+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
105105
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest')
106106
})
107107
it('should not be normalized if web+ipns:/{foo}', function () {
108-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bipns%3A%2Fipfs.io%3FargTest%23hashTest')
108+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bipns%3A%2Fipfs.io%3FargTest%23hashTest')
109109
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
110110
})
111111
it('should be normalized if web+ipns://{foo}', function () {
112-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bipns%3A%2F%2Fipfs.io%3FargTest%23hashTest')
112+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bipns%3A%2F%2Fipfs.io%3FargTest%23hashTest')
113113
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest')
114114
})
115115
it('should be normalized if web+dweb:/ipfs/{CID}', function () {
116-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bdweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
116+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bdweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
117117
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest')
118118
})
119119
it('should not be normalized if web+dweb://ipfs/{CID}', function () {
120-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bdweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
120+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bdweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
121121
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
122122
})
123123
it('should be normalized if web+dweb:/ipns/{foo}', function () {
124-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bdweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest')
124+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bdweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest')
125125
expect(modifyRequest.onBeforeRequest(request).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest')
126126
})
127127
it('should not be normalized if web+dweb://ipns/{foo}', function () {
128-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bdweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest')
128+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bdweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest')
129129
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
130130
})
131131
it('should not be normalized if web+{foo}:/bar', function () {
132-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bfoo%3A%2Fbar%3FargTest%23hashTest')
132+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bfoo%3A%2Fbar%3FargTest%23hashTest')
133133
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
134134
})
135135
it('should not be normalized if web+{foo}://bar', function () {
136-
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bfoo%3A%2F%2Fbar%3FargTest%23hashTest')
136+
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bfoo%3A%2F%2Fbar%3FargTest%23hashTest')
137137
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
138138
})
139139
})

0 commit comments

Comments
 (0)