diff --git a/add-on/manifest.json b/add-on/manifest.json
index 4c87c693e..83839d25d 100644
--- a/add-on/manifest.json
+++ b/add-on/manifest.json
@@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_manifest_extensionName__",
"short_name": "__MSG_manifest_shortExtensionName__",
- "version" : "2.1.0",
+ "version" : "2.1.1",
"description": "__MSG_manifest_extensionDescription__",
"homepage_url": "https://github.com/ipfs/ipfs-companion",
diff --git a/add-on/src/lib/ipfs-request.js b/add-on/src/lib/ipfs-request.js
index fa0423b07..f9e859e0c 100644
--- a/add-on/src/lib/ipfs-request.js
+++ b/add-on/src/lib/ipfs-request.js
@@ -13,6 +13,11 @@ function createRequestModifier (getState, dnsLink, ipfsPathValidator) {
return
}
+ // skip all local requests
+ if (request.url.startsWith('http://127.0.0.1:') || request.url.startsWith('http://localhost:')) {
+ return
+ }
+
// poor-mans protocol handlers - https://github.com/ipfs/ipfs-companion/issues/164#issuecomment-328374052
if (state.catchUnhandledProtocols && mayContainUnhandledIpfsProtocol(request)) {
const fix = normalizedUnhandledIpfsProtocol(request, state.pubGwURLString)
diff --git a/add-on/src/lib/options.js b/add-on/src/lib/options.js
index 1ec63772e..ec3a5771b 100644
--- a/add-on/src/lib/options.js
+++ b/add-on/src/lib/options.js
@@ -9,8 +9,8 @@ const optionDefaults = Object.freeze({
preloadAtPublicGateway: true,
catchUnhandledProtocols: true,
displayNotifications: true,
- customGatewayUrl: 'http://127.0.0.1:8080',
- ipfsApiUrl: 'http://127.0.0.1:5001',
+ customGatewayUrl: 'http://localhost:8080',
+ ipfsApiUrl: 'http://localhost:5001',
ipfsApiPollMs: 3000
})
@@ -42,3 +42,12 @@ function storeMissingOptions (read, defaults, storage) {
}
exports.storeMissingOptions = storeMissingOptions
+
+function normalizeGatewayURL (url) {
+ // https://github.com/ipfs/ipfs-companion/issues/291
+ return url
+ .replace('/127.0.0.1:', '/localhost:')
+ .replace('/gateway.ipfs.io', '/ipfs.io')
+}
+
+exports.normalizeGatewayURL = normalizeGatewayURL
diff --git a/add-on/src/options/options.js b/add-on/src/options/options.js
index 4c14196b4..35ed33925 100644
--- a/add-on/src/options/options.js
+++ b/add-on/src/options/options.js
@@ -2,7 +2,7 @@
/* eslint-env browser, webextensions */
const browser = require('webextension-polyfill')
-const { optionDefaults } = require('../lib/options')
+const { optionDefaults, normalizeGatewayURL } = require('../lib/options')
const translateDataAttrs = require('../lib/data-i18n')
translateDataAttrs()
@@ -18,9 +18,11 @@ async function saveOption (name) {
switch (element.type) {
case 'text':
case 'number':
- case 'url':
change[name] = element.value
break
+ case 'url':
+ change[name] = normalizeGatewayURL(element.value)
+ break
case 'textarea':
// normalize input into a string of entries separated by a single space
change[name] = element.value.replace(/[\r\n,;]+/g, ' ').replace(/ +(?= )/g, '').trim()
diff --git a/add-on/src/popup/browser-action/gateway-status.js b/add-on/src/popup/browser-action/gateway-status.js
index 2fa8ca3e4..9e4cd8393 100644
--- a/add-on/src/popup/browser-action/gateway-status.js
+++ b/add-on/src/popup/browser-action/gateway-status.js
@@ -15,7 +15,7 @@ module.exports = function gatewayStatus ({
-
${browser.i18n.getMessage('panel_statusGatewayAddress')}
- ${gatewayAddress == null ? 'unknown' : gatewayAddress}
+ ${gatewayAddress == null ? 'unknown' : gatewayAddress}
-
${browser.i18n.getMessage('panel_statusGatewayVersion')}
diff --git a/test/functional/lib/ipfs-request.test.js b/test/functional/lib/ipfs-request.test.js
index 0af06455f..9e7ca1e9e 100644
--- a/test/functional/lib/ipfs-request.test.js
+++ b/test/functional/lib/ipfs-request.test.js
@@ -25,7 +25,7 @@ describe('modifyRequest', function () {
peerCount: 1,
redirect: true,
catchUnhandledProtocols: true,
- gwURLString: 'http://127.0.0.1:8080'
+ gwURLString: 'http://localhost:8080'
})
const getState = () => state
dnsLink = createDnsLink(getState)
@@ -36,7 +36,7 @@ describe('modifyRequest', function () {
describe('request for a path matching /ipfs/{CIDv0}', function () {
it('should be served from custom gateway if redirect is enabled', function () {
const request = url2request('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest')
- expect(modifyRequest(request).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest')
+ expect(modifyRequest(request).redirectUrl).to.equal('http://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest')
})
it('should be left untouched if redirect is disabled', function () {
state.redirect = false
@@ -57,12 +57,12 @@ describe('modifyRequest', function () {
dnsLink.readDnslinkFromTxtRecord = sinon.stub().withArgs(fqdn).returns('/ipfs/Qmazvovg6Sic3m9igZMKoAPjkiVZsvbWWc8ZvgjjK1qMss')
// pretend API is online and we can do dns lookups with it
state.peerCount = 1
- expect(modifyRequest(request).redirectUrl).to.equal('http://127.0.0.1:8080/ipns/ipfs.git.sexy/index.html?argTest#hashTest')
+ expect(modifyRequest(request).redirectUrl).to.equal('http://localhost:8080/ipns/ipfs.git.sexy/index.html?argTest#hashTest')
})
it('should be served from custom gateway if {path} starts with a valid CID', function () {
const request = url2request('https://ipfs.io/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest')
dnsLink.readDnslinkFromTxtRecord = sinon.stub().returns(false)
- expect(modifyRequest(request).redirectUrl).to.equal('http://127.0.0.1:8080/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest')
+ expect(modifyRequest(request).redirectUrl).to.equal('http://localhost:8080/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest')
})
it('should be left untouched if redirect is disabled', function () {
state.redirect = false
@@ -216,6 +216,22 @@ describe('modifyRequest', function () {
})
})
+ describe('request for IPFS path at a localhost', function () {
+ // we do not touch local requests, as it may interfere with other nodes running at the same machine
+ // or could produce false-positives such as redirection from 127.0.0.1:5001/ipfs/path to localhost:8080/ipfs/path
+ it('should be left untouched if 127.0.0.1 is used', function () {
+ state.redirect = false
+ const request = url2request('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/')
+ expect(modifyRequest(request)).to.equal(undefined)
+ })
+ it('should be left untouched if localhost is used', function () {
+ // https://github.com/ipfs/ipfs-companion/issues/291
+ state.redirect = false
+ const request = url2request('http://localhost:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/')
+ expect(modifyRequest(request)).to.equal(undefined)
+ })
+ })
+
after(() => {
delete global.URL
})