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: ipfs:// in Firefox incognito window #835

Merged
merged 1 commit into from
Dec 12, 2019
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
12 changes: 6 additions & 6 deletions add-on/manifest.firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@
{
"protocol": "web+dweb",
"name": "IPFS Companion: DWEB Protocol Handler",
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
},
{
"protocol": "web+ipns",
"name": "IPFS Companion: IPNS Protocol Handler",
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
},
{
"protocol": "web+ipfs",
"name": "IPFS Companion: IPFS Protocol Handler",
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
},
{
"protocol": "dweb",
"name": "IPFS Companion: DWEB Protocol Handler",
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
},
{
"protocol": "ipns",
"name": "IPFS Companion: IPNS Protocol Handler",
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
},
{
"protocol": "ipfs",
"name": "IPFS Companion: IPFS Protocol Handler",
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#%s"
"uriTemplate": "https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#%s"
}
]
}
2 changes: 1 addition & 1 deletion add-on/src/lib/ipfs-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ function isSafeToRedirect (request, runtime) {

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

function redirectingProtocolRequest (request) {
return request.url.startsWith(redirectingProtocolEndpoint)
Expand Down
38 changes: 19 additions & 19 deletions test/functional/lib/ipfs-request-protocol-handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,81 +59,81 @@ describe('modifyRequest.onBeforeRequest:', function () {

// without web+ prefix (Firefox > 59: https://github.com/ipfs-shipyard/ipfs-companion/issues/164#issuecomment-356301174)
it('should not be normalized if ipfs:/{CID}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
})
it('should be normalized if ipfs://{CID}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest')
})
it('should not be normalized if ipns:/{fqdn}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#ipns%3A%2Fipfs.io%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#ipns%3A%2Fipfs.io%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
})
it('should be normalized if ipns://{fqdn}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#ipns%3A%2F%2Fipfs.io%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#ipns%3A%2F%2Fipfs.io%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest')
})
it('should be normalized if ipfs://{fqdn}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#ipfs%3A%2F%2Fipfs.io%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#ipfs%3A%2F%2Fipfs.io%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest')
})
it('should be normalized if dweb:/ipfs/{CID}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#dweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#dweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest')
})
it('should not be normalized if dweb://ipfs/{CID}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#dweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#dweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
})
it('should be normalized if dweb:/ipns/{foo}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#dweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#dweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest')
})
it('should not be normalized if dweb://ipns/{foo}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#dweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#dweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
})

// web+ prefixed versions (Firefox < 59 and Chrome)
it('should not be normalized if web+ipfs:/{CID}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
})
it('should be normalized if web+ipfs://{CID}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest')
})
it('should not be normalized if web+ipns:/{foo}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bipns%3A%2Fipfs.io%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bipns%3A%2Fipfs.io%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
})
it('should be normalized if web+ipns://{foo}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bipns%3A%2F%2Fipfs.io%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bipns%3A%2F%2Fipfs.io%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest')
})
it('should be normalized if web+dweb:/ipfs/{CID}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bdweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bdweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest')
})
it('should not be normalized if web+dweb://ipfs/{CID}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bdweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bdweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
})
it('should be normalized if web+dweb:/ipns/{foo}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bdweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bdweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest')
})
it('should not be normalized if web+dweb://ipns/{foo}', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bdweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bdweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
})
it('should not be normalized if web+{foo}:/bar', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bfoo%3A%2Fbar%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bfoo%3A%2Fbar%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
})
it('should not be normalized if web+{foo}://bar', function () {
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiegmsbyyxqe3otwyymguym5sflugdf2bnfh75sk3rqcfgvnyatgry#web%2Bfoo%3A%2F%2Fbar%3FargTest%23hashTest')
const request = url2request('https://gateway.ipfs.io/ipfs/bafkreiewrj2pugsghd3flw2lk2fhvtmz6wipecnxep5qc5m3lfpf2mvjk4#web%2Bfoo%3A%2F%2Fbar%3FargTest%23hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
})
})
Expand Down