From 0c9797c08bf55fe63f029b5fd8e47d5effc2478c Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 2 Jan 2019 11:59:15 +0100 Subject: [PATCH 1/4] feat: warn about mixed content issues Closes #648 --- add-on/_locales/en/messages.json | 4 ++++ add-on/src/options/forms/gateways-form.js | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/add-on/_locales/en/messages.json b/add-on/_locales/en/messages.json index c97e29ebf..21f673adb 100644 --- a/add-on/_locales/en/messages.json +++ b/add-on/_locales/en/messages.json @@ -239,6 +239,10 @@ "message": "URL of preferred HTTP2IPFS Gateway", "description": "An option description on the Preferences screen (option_customGatewayUrl_description)" }, + "option_customGatewayUrl_warning": { + "message": "Warning: IPFS content can be blocked from loading on HTTPS websites unless your gateway URL starts with “http://127.0.0.1” or “https://”", + "description": "A warning on the Preferences screen, displayed when URL does not belong to Secure Context (option_customGatewayUrl_warning)" + }, "option_useCustomGateway_title": { "message": "Use Custom Gateway", "description": "An option title on the Preferences screen (option_useCustomGateway_title)" diff --git a/add-on/src/options/forms/gateways-form.js b/add-on/src/options/forms/gateways-form.js index 56c211186..8295a1bdc 100644 --- a/add-on/src/options/forms/gateways-form.js +++ b/add-on/src/options/forms/gateways-form.js @@ -5,6 +5,10 @@ const browser = require('webextension-polyfill') const html = require('choo/html') const { normalizeGatewayURL } = require('../../lib/options') +// Warn about mixed content issues when changing the gateway +// https://github.com/ipfs-shipyard/ipfs-companion/issues/648 +const secureContextUrl = /^https:\/\/.*|^http:\/\/127.0.0.1/ + function gatewaysForm ({ ipfsNodeType, customGatewayUrl, @@ -15,6 +19,7 @@ function gatewaysForm ({ const onCustomGatewayUrlChange = onOptionChange('customGatewayUrl', normalizeGatewayURL) const onUseCustomGatewayChange = onOptionChange('useCustomGateway') const onPublicGatewayUrlChange = onOptionChange('publicGatewayUrl', normalizeGatewayURL) + const mixedContentWarning = !secureContextUrl.test(customGatewayUrl) return html`
@@ -25,7 +30,9 @@ function gatewaysForm ({ + ` : null} ${ipfsNodeType === 'external' ? html` From 37b908c45ffaf766f6b0e79d46304939d709b5ed Mon Sep 17 00:00:00 2001 From: Oli Evans Date: Wed, 2 Jan 2019 12:39:43 +0100 Subject: [PATCH 2/4] Update add-on/_locales/en/messages.json Co-Authored-By: lidel --- add-on/_locales/en/messages.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-on/_locales/en/messages.json b/add-on/_locales/en/messages.json index 21f673adb..1359385ca 100644 --- a/add-on/_locales/en/messages.json +++ b/add-on/_locales/en/messages.json @@ -240,7 +240,7 @@ "description": "An option description on the Preferences screen (option_customGatewayUrl_description)" }, "option_customGatewayUrl_warning": { - "message": "Warning: IPFS content can be blocked from loading on HTTPS websites unless your gateway URL starts with “http://127.0.0.1” or “https://”", + "message": "IPFS content will be blocked from loading on HTTPS websites unless your gateway URL starts with “http://127.0.0.1” or “https://”", "description": "A warning on the Preferences screen, displayed when URL does not belong to Secure Context (option_customGatewayUrl_warning)" }, "option_useCustomGateway_title": { From 6f585e4b3cb48023b5ef01ab3d846c1a9d12b807 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 2 Jan 2019 12:40:43 +0100 Subject: [PATCH 3/4] Update messages.json --- add-on/_locales/en/messages.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-on/_locales/en/messages.json b/add-on/_locales/en/messages.json index 1359385ca..843a254ec 100644 --- a/add-on/_locales/en/messages.json +++ b/add-on/_locales/en/messages.json @@ -240,7 +240,7 @@ "description": "An option description on the Preferences screen (option_customGatewayUrl_description)" }, "option_customGatewayUrl_warning": { - "message": "IPFS content will be blocked from loading on HTTPS websites unless your gateway URL starts with “http://127.0.0.1” or “https://”", + "message": "IPFS content will be blocked from loading on HTTPS websites unless your gateway URL starts with “http://127.0.0.1” or “https://”", "description": "A warning on the Preferences screen, displayed when URL does not belong to Secure Context (option_customGatewayUrl_warning)" }, "option_useCustomGateway_title": { From d479bed02c5a909b10c4a1b4b44fb8d98ac6ab92 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 3 Jan 2019 15:55:15 +0100 Subject: [PATCH 4/4] fix: support ipv6 in mixed-content check --- add-on/_locales/en/messages.json | 2 +- add-on/src/options/forms/gateways-form.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/add-on/_locales/en/messages.json b/add-on/_locales/en/messages.json index 843a254ec..2d6730b9e 100644 --- a/add-on/_locales/en/messages.json +++ b/add-on/_locales/en/messages.json @@ -240,7 +240,7 @@ "description": "An option description on the Preferences screen (option_customGatewayUrl_description)" }, "option_customGatewayUrl_warning": { - "message": "IPFS content will be blocked from loading on HTTPS websites unless your gateway URL starts with “http://127.0.0.1” or “https://”", + "message": "IPFS content will be blocked from loading on HTTPS websites unless your gateway URL starts with “http://127.0.0.1”, “http://[::1]” or “https://”", "description": "A warning on the Preferences screen, displayed when URL does not belong to Secure Context (option_customGatewayUrl_warning)" }, "option_useCustomGateway_title": { diff --git a/add-on/src/options/forms/gateways-form.js b/add-on/src/options/forms/gateways-form.js index 8295a1bdc..dddc87a41 100644 --- a/add-on/src/options/forms/gateways-form.js +++ b/add-on/src/options/forms/gateways-form.js @@ -7,7 +7,7 @@ const { normalizeGatewayURL } = require('../../lib/options') // Warn about mixed content issues when changing the gateway // https://github.com/ipfs-shipyard/ipfs-companion/issues/648 -const secureContextUrl = /^https:\/\/.*|^http:\/\/127.0.0.1/ +const secureContextUrl = /^https:\/\/|^http:\/\/127.0.0.1|^http:\/\/\[::1\]/ function gatewaysForm ({ ipfsNodeType,